简体   繁体   中英

How to include app config file in WAR archive?

I'm having trouble deploying a Java web app. It centers on our application config file (myapp.properties). In certain situations, having this file external to the WAR seems to work fine, but whenever I try to deploy it properly (Docker, proper JBoss deployment, etc.) the deployments inevitably fail due to being unable to find/read from myapp.properties.

I've seen a few references here and elsewhere to packaging these files inside the WAR archive, but I can't find any information on how to actually do that. So, my questions is:

What is the proper way to include an application config file in a WAR archive and/or deployment?

It depends in how you want to access the file.

If you want to load it via classloader resources, you need it to be in the class-path, so the best location is inside WEB-INF/classes .

That's by the way, where resources in src/main/resources will end up if you are using Maven

You can also put it anywhere inside your WAR, for example, WEB-INF/config and access it via ServletContext.getResourceAsStream("/WEB-INF/config/.... . Beware but, that it's not inside the WEB-INF directory, you will have to explicitly forbid the access to the file in the web.xml deployement descriptor, otherwise it would be accessible to client requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM