How to prevent file locking when undeploying a Tomcat web app?

I have come across the same problem in Apache Tomcat/8.0.5. I did the following steps using manager App and it worked for me.

  • Close the browser including all tabs (to delete cache).
  • Re-open the 'Manager App' and first make sure that the application is stopped (start button should be enabled).
  • Now click on undeploy.

I think when we directly click on undeploy, first it locks the jars, stops the application and try to undeploy but fails with FAIL - Unable to delete message.

If you really confused with status, close the browser, restart tomcat, open 'manager App', click on stop and then undeploy.


This is very common in Windows environment but there is a solution via the antiResourceLocking context property:

Open context.xml from /tomcat/conf folder and modify the context to match this :

<Context antiResourceLocking="true">

Edit: Updated properties following @JanM comment. Previously it also contained 'antiJARLocking'


This is one of the common issues with tomcat. Tomcat server catches hold of the resources on startup and deploys it. While undeploying, some resource would still be in use by tomcat. It would not yet have released the resource, but at the same time, another thread in tomcat would try to cleanup the same resources. Hence, the deletion of those resources would fail. One best way is to clean up the application's root directory in webapps manually.