[java] How to purge tomcat's cache when deploying a new .war file? Is there a config setting?

I have a simple hello, world servlet application that I am just playing around with, and pushing it out to my tomcat server on a VPS.

When I make a change to my code, and deploy it, tomcat doesn't serve the newly published code (even after starting the service again).

I stop the service, then push the new war file to /webapps/, and I make sure to delete the old exploded folder also.

When I re-start the server, it still serves the older codebase.

Is there a setting in the config to stop this behaviour?

Also, what folders would I have to delete? Please be specific (folders and paths) as I have tried deleting some and havent' gotten anywhere.

This question is related to java tomcat

The answer is


I encountered some weird behaviour that did not reflect the actual code base so after some time trying several solutions, my problem was solved by manually deleting everything under /var/cache/tomcat8/


A little late for the party, here's how I do it

  1. Undeploy application from manager
  2. Shutdown tomcat using ./shutdown.sh
  3. Delete browser cache
  4. Delete the application from webapps, and from /work/Catalina/...
  5. Startup tomcat using ./startup.sh
  6. Copy the new version of the application into /webapps and start it.

I'd add that in case of really odd behavior - where you spend a couple of hours saying WTF - try manually deleting the /webapps/yourwebapp/WEB-INF/classes directory. A java source file that was moved to another package will not have its compiled class file deleted - at least in the case of an exploded web-application on TC. This can seriously drive you crazy with unpredictable behavior, especially with an annotated servlet.


I have a bad time putting my war file at /etc/tomcat7/webapps but the real path was /var/lib/tomcat7/webapps. May you want to use sudo find / -type f -name "my-war-file.war" to know where is it.

And remove this folders /tmp/hsperfdata_* and /tmp/tomcat7-tomcat7-tmp.


Tomcat also creates a ROOT directory at the same level as work/. ROOT/ also caches the old stuff. delete ROOT along with Catalina directory in work.


I'm new to tomcat, and this problem was driving me nuts today. It was sporadic. I asked a colleague to help, and the WAR expanded and it did was it was supposed to. 3 deploys later that day, it reverted back to the original version.

In my case, the MySite.WAR got expanded to both ROOT AND MySite. MySite was usually served up. But sometimes tomcat decided it liked the ROOT one better and all my changes disappeared.

The "solution" is to delete the ROOT website with every deploy of the war.


I had the same issue twice, but in the second time I realized it wasn't a problem on Tomcat at all.. Try to delete the cache of your browser, refresh the page and see if the new version of the page on your server is being shown up. It worked with me.


Seems a timestamp issue. According to tomcat documentation, if there is a new jsp or servlet this will create a new _java file in the work folder unless the _java.class files are newer than the jsp or servlets.


Sounds like your class loader is not loading the servlet classes once they are updated. This might be fixed if you change your web.xml file which should prompt the server/container to re-deploy and reload the servlet classes. I guess add an empty line at the end of your web.xml and save it and then see if that fixes it. As i said this might fix it or might not.

Good luck!