Tomcat deployment overwrites context.xml

tomcatweb-applications

I'm pretty new to Tomcat in general, so please point out if got anything wrong.

My question is regarding updates to already deployed apps, using the Tomcat manager. But first thing first. I'm using the META-INF/Context.xml for storing connection info for the database connections, so this is unique to every server the application is deployed to. I'm not sure if this is optimal but it's the only way I know.

So, when updating the application, it's important that this file doesn't get modified, because I don't want to have to go in and remake all changes every time I update my app.

For updating, I'm using the Tomcat Manager, and I've tried different approaches but everything seems to build on the process of undeploy, then deploy the new version. This way, the Context.xml gets removed/replaced by an empty Context.xml file.

So my question is basically, how do I update a running webapp, and at the same time having the Context.xml left untouched?

Btw, I'm running Tomcat 6.0.24.

Best Answer

The setup up I'm currently working with has multiple contexts running the same webapp and each context has different database settings (similar to your setup except each context is running on a different server).

Instead of including the context.xml file in META-INF you can create a context.xml specifically for each instance on each server and put it in the $TOMCAT_ROOT$/conf/Catalina/localhost. When Tomcat starts the context any settings in the Catalina/localhost/context.xml will override those set in your web app (either through your WEB-INF/web.xml file or your META-INF/context.xml file).

We have had some small issues with this however were Parameters defined in the Catalina/localhost/context.xml are not properly overriding the ones defined in the web app but this is easily resolved by adding the override attribute to the Parameter node like so:

<Parameter name="foo" value="bar" override="1"/>

The docs for tomcat contexts describes a lot of this in more detail.