views:

41

answers:

2

I am building a web service and am packaging it into a war file for deployment. Right now all of my config files (.properties and .xml) are being packaged into my .war file. This isn't going to work as some of these files will need to be modified for each individual installation. I know that some servlet containers will leave the .war files intact which would mean the config files would never be easily modified. My question is this: what is the best practice for deploying a .war file with these external config files? I'm thinking that the config files will need to be shipped separate from the .war file and placed into a directory that is in the classpath. Is there a default directory setup like this in Tomcat that these files can just be dropped into and my web service will be able to find without much trouble?

Maybe I shouldn't be using a war file for this setup? Maybe I should just be providing a zip file (with the same contents as the war file) and the deployment will simply be to extract the zip into the webapps directory?

A: 

I do not know any default directory in Tomcat to store configuration, my attempts to solve the same issue have been :

1 - Move configuration to the DB and provide scripts or webpages to modify values.
2 - Have a script to deploy the war. The script would merge configuration from a user directory into web.xml or other deployed config files.
3 - Have webapps look first in a user directory for configuration and if not found then look for configuration files deployed by the war.

Least favorite is 3 - it require all webapps to check two places for configuration and you end up with two different xml files on the server with different values and it is not always clear which one is used.

Next favorite is 2 - the webapps can be written without knowledge of multiple config files, but you run into issue when someone does a deploy from Tomcat manager instead of using your script.

Favorite is 1. This just works in most cases. Problem is when you don't have a DB or want to configure how you connect to the DB.

GregB
I think I am going to avoid war file deployment altogether and instead use a zip that will need to be extracted in order to install the app. This avoids this headache altogether.
Dennis
How does extracting a zip prevent configuration from being overwritten when an upgrade is performed?
GregB
You're right, it doesn't solve that problem. But at least allows the files to be manually edited and the old ones to be saved. Not ideal but better than "hiding" everything in the war file with little control over the config at deploy time.
Dennis
A: 

If having the file visible from all webapps is not an issue, you could put it $CATALINA_HOME/lib.

Pascal Thivent