You should put the configuration files under the WEB-INF
folder. 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-INF
is important, so the files are not "accessible" by the browser.
Another way could be to add a parameter to the web.xml
configuration, where you specify the location of your configuration files so they are not inside the webapps directory. You could do this by adding a context-param
. For example:
<context-param>
<param-name>configuration</param-name>
<param-value>/var/myapp/config</param-value>
</context-param>
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 getInitParameter
method from the ServletContext
).
But this will only work for config files, which are not needed in the classpath.