I am developing a jsp + servlet application, package to war, deploy to tomcat 8.
I know WEB-INF is the folder to store files which are not to be served, only processed at server side: like html or jsp fragments, etc. I need to store some xmls. Servlets would read those xmls when processing requests.
The question is:
should I store these xmls in the same WEB-INF folder? Or is there a special place for that? I don't want to do it very anti-pattern.
If you are using maven, you could put your XML files in src/main/resources. When packaged as a WAR, they will be placed in the WAR's WEB-INF/classes folder, e.g.
src/main/resources/settings.xml
Will get packaged to:
WEB-INF/classes/settings.xml
That way you can read the file using e.g.:
MyServlet.class.getResourceAsStream("/settings.xml");
Once deployed to tomcat and it gets unpacked, you can then edit / update the settings.xml in the WEB-INF/classes folder if you need to. Note that the /WEB-INF/classes folder is the root of the classpath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With