Tuesday, May 06, 2008

Getting tomcat to stop deleting your context xml files

I've been plagued with this annoying problem in tomcat for about a year, and it has been driving me crazy. I've looked through the code, joined the mailing list, etc. etc. The problem is when you have context xml files, such as /usr/local/tomcat/conf/Catalina/localhost/app.xml. Generally, you would use such files to set up JNDI data sources for database connections, but I also use them to set up configuration beans in order to keep environment-specific data outside of your application code (which I consider the whole war file to be). Anyway, tomcat seems to randomly delete those files when I change anything in the application files. I tried various configurations using war files, no war files, and war files in funny locations, and it happened to all of them.

I never did find out why it deletes the files, but I did find a solution, thanks to a user on the tomcat mailing list. All you have to do is turn off "autoDeploy" on the "Host". Basically, you need to edit /usr/local/tomcat/conf/server.xml and change the xml element, so that it says autoDeploy="false" instead of autoDeploy="true". And with that, all my problems are over.

4 comments:

Adam said...

Thanks for the tip. I've been experiencing this issue for at least a year as well :)

Wade said...

I too am experiencing this frustration. I am looking for a way to deploy application-specific contexts without having to hard-code them into server.xml or putting the context info into the WAR file. However, I am also reluctant to give up the copy-war-file deployment feature in order to address this problem. We are just too addicted to that way of deployment.

MattChurchy said...

I've had these driving me crazy for 2 years! Our sys admin was almost making out that i was imaging it.

Cheers Matt.

Anonymous said...

According to one of my developers the file gets deleted because Tomcat was not shut down properly prior to doing a restart of the server. Do you know if this applies to your situation?

Cheers,
Kohlman