简体   繁体   中英

Java servlet access to config file

I am deploying a war file to glassfish and would like to know if it is possible to have a file that can have properties stored in them that can be accessed within my web methods. The catch is I would like to change the file as business requests change wihtout having to recompile. I could store it in the DB or have it as system properties on glassfish itself but would like to know if the file way is possible.

I have read these but all seems like you would have to recompile?:

Load properties file in Servlet/JSP

loading properties file in init() of servlet without using context-param tag in web.xml

Sure you can. You can load the properties at startup and note the modification time for the file; then you can reload the properties again when the modification time has changed, ie when someone has edited it. The check and reload can be done using a background thread or on access, but take care to handle synchronization as all simultaneous requests will compete with each other.

I'd keep the file outside of Glassfish and point to it using a system property or context parameter, but you can also edit the properties file where Glassfish has extracted the WAR file.

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