Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of raw resources in Tomcat webapp [duplicate]

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.

like image 225
Androrider Avatar asked Nov 16 '25 16:11

Androrider


1 Answers

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.

like image 137
Willy du Preez Avatar answered Nov 18 '25 06:11

Willy du Preez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!