Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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...

share|improve this question

4 Answers

up vote 3 down vote accepted

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

share|improve this answer
This is not a complete answer - see serverfault.com/faq#deletion – Jenny D Feb 27 at 13:01
:) please help yourself (seems the syntax highlighting works slightly different than in stackoverflow which deleted part of the answer before) – Jan Zyka Feb 27 at 14:41
The thing is that if you just add a link, the target of the link may disappear, making the answer useless. That's why serverfault.com encourages you to post the actual answer instead of just the link. And when I commented, the rest of the text wasn't visible. I'd still recommend actually posting a more complete response rather than a brief summary of the link. – Jenny D Feb 27 at 15:21
That's simply not true. The original answer contained (and still does) short summary of what you can find under the link. Without the link the answer still make perfect sense and together with the link you can find details. – Jan Zyka Feb 27 at 15:35
But I didn't plan to be offensive so sorry if it sounded like that :) I'm not much into this web, just was solving the same and wanted to share. – Jan Zyka Feb 27 at 15:38
show 5 more comments

Cant answer the Why bit.

However, This link states you can stop this by setting the autoDeploy="false" in server.xml

share|improve this answer

I honestly dont know what the reasoning behind Tomcat doing this is but try adding the following XML attribute to your context element

reloadable="false"

So your context could look something like this:

<Context path="/" docBase="/some/path/name" reloadable="false">
<!-- Context related stuff -->
</Context>

This should keep Tomcat from deleting the file

share|improve this answer
Unfortunately, that makes development harder as I would have to restart Tomcat after each build. – staticsan Oct 20 '10 at 22:42
checkout jrebel to help with this in development: zeroturnaround.com/jrebel – harmanjd Dec 8 '11 at 16:33

Have this problem to. Seems like when you replace your war it causes undeployment of the app which causes deletion of the context file. I don't have a work-around but would love to have one which is more convenient than reloadable=false

http://stackoverflow.com/questions/4032773/why-does-tomcat-replace-context-xml-on-redeploy

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.