Why does tomcat like deleting my context.xml file?

I'm developing a web-based Java application at work and (obviously) have to run it locally during development. I've figured out the Tomcat docs and have a suitable context.xml file in /etc/tomcat6/Catalina/localhost/ but every so often, Tomcat decides to delete it! Which means I have to put it back and restart Tomcat.

Why does it do this? I have searched the Tomcat docs about it and am none the wiser.

(Oh yes: it's not actually called context.xml but owners.xml as that's the HTTP path prefix for this application.)

Update

I've now seen Tomcat delete the file whilst Tomcat was running. I think I need to file a bug...


Quick summary: there are several conditions (like changing the war file, deleting the webapp or replacing it with new content) under which tomcat will undeploy the context including removing the context file.

Details: Whether tomcat does or doesn't do autoDeployment (means checking for changes in your .xml descriptor as well as checking changes in the webapp directory) is driven by:

  1. server.xml localted in $CATALINA_HOME/conf/server.xml section:

    <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

  2. You can also set this property in your context file overloading the value

Quoting the doc for cases when autoDeploy=true may cause removal of your context file:

  • Deleting a WAR file will trigger an undeploy of the application with the removal of any associated expanded directory, context file and work directory.
  • Deleting a directory will trigger an undeploy of the application with the removal of any associated context file and work directory.
  • Updating a WAR file will trigger an undeploy of the application with the removal of any associated expanded directory, context file and work directory.
  • Updating a directory (not the directory contents) will trigger an undeploy of the application with the removal of any associated context file and work directory.

Exhaustive details: http://tomcat.apache.org/tomcat-6.0-doc/config/host.html#Automatic%20Application%20Deployment


If you don't want autoDeploy feature, in production environments for instance, you may consider the following attributes in the conf/Catalina/localhost context file :

  • autoDeploy="false"
  • and deployXML="false"

autoDeploy="false" may not work alone because application context.xml (in META-INF) can override server.xml settings of autoDeploy.

  • The application's META-INF/context.xml will be used in development environment, with autoDeploy
  • The conf/Catalina/localhost context in production, without autoDeploy.

deployXML attribute documentation attribute documentation is worth reading (§ Standard Implementation).

Exhaustive autoDeploy user case, and when context is removed : i.e. application undeployed, user case is documented can be found here.