Why does tomcat like deleting my context.xml file?
Solution 1:
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:
server.xml localted in $CATALINA_HOME/conf/server.xml section:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
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
Solution 2:
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.
Solution 3:
Cant answer the Why bit.
However, This link states you can stop this by setting the autoDeploy="false"
in server.xml