Where to put j2ee web app's application-specific config/properties/APP_HOME?
#1 - Where is the common location for storing web app configuration that needs to persist after the app is restarted and redeployed? It must be somewhere outside the web app's directory in order to avoid being overwritten when a new war is deployed. One example I have found is to always use $HOME/.my_app_name for the user that started web container, but what if the user 开发者_开发问答changes? All configuration would be lost.
#2 - What is the common way to inform my webapp of this location if it is dynamic?
This is the only example I have been able to find, but I have not found any formal instructions for this being standard. http://wiki.hudson-ci.org/display/HUDSON/Administering+Hudson
I understand that it needs to be writable? So the classpath is out of question.
Provide the path as a JVM startup argument:
-Dconfig.location="/path/to/config/files"
This way it's available by System#getProperty()
.
String configLocation = System.getProperty("config.location");
File configFile = new File(configLocation, "config.properties");
// ...
Document it properly in the installation/usage manual of your webapp. Implement your code accordingly that it throws a crystal clear runtime exception whenever that property is missing or that the path does not exist or is not writable so that it can easily be fixed by the sysadmin.
精彩评论