Are there any recommendations on how to keep an application level settings/configuration file in a J2EE project? I have a web project that has dependences that must write to the logs, and a local settings file. Is there anyway to store the settings file in the local directory and have it writable?
[Some of the dependencies are: hibernate and gridgain, so they produce a lot of logs]
I would rather not hard code the location of the settings file.
You should put the configuration files under the
WEB-INFfolder. You could create a directory/WEB-INF/config. If they should be in the classpath put them to/WEB-INF/classes. By doing it this way, the location is not hardcoded, but at a well known place for your application.Putting them inside
/WEB-INFis important, so the files are not “accessible” by the browser.Another way could be to add a parameter to the
web.xmlconfiguration, where you specify the location of your configuration files so they are not inside the webapps directory. You could do this by adding acontext-param. For example:The value will be made visible to your web application as a servlet context initialization parameter named configuration. You can then use it as a base path to read your configuration files (Get the value by calling the
getInitParametermethod from theServletContext).But this will only work for config files, which are not needed in the classpath.