Where should configuration files be stored in a web application?

Alex Chaffee

The current servlet spec (2.2) doesn't mention specifically where to store configuration files. The new version (2.3) will have a more explicit way of accessing them.

In the meantime, a good technique is to put them in the *root* level of your WEB-INF/classes directory. (e.g. "mywebapp/WEB-INF/classes/config.txt".) Since this directory is automatically on your classpath, you can load the files using

InputStream in = this.getClass().getResourceAsStream("/" + filename);
if (in == null)
    throw new IOException("Resource " + filename + " not found");
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact