78

I am using the manager app in tomcat 7, and i am unable to undeploy an application completely.

It says FAIL - Unable to delete [F:\apache-tomcat-7.0.33\webapps\balaji]. The continued presence of this file may cause problems.

I read somewhere its because of some phenomenon called memory leak , and if we fix it the issue will be solved.

Can anyone tell me what is this memory leak in tomcat 7, and how can we fix it ?? I am using windows 7 OS. If i am able to fix it will my un-deploy and re-deploy process run smooth ?

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
bali208
  • 2,257
  • 7
  • 40
  • 43
  • Since I came to this question with a similar issue. But what I found out was that we were reading some files and not closing them and hence they were not deleted on redeploy. So rather than trying other solutions, have a look at the code and see how you are using the files that are not getting deleted. – awsome May 17 '18 at 14:14

4 Answers4

134

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'

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
mvlupan
  • 3,536
  • 3
  • 22
  • 35
  • Does it only occur in Windows? Tomcat is based on Java, and I'm seeing similar problems on Ubuntu with Tomcat. – icedwater Sep 12 '13 at 08:49
  • 2
    I only said that is common for Windows, at least that was the case for me and people I know. It could very well be the same case for Ubuntu. – mvlupan Sep 13 '13 at 12:17
  • 10
    From http://tomcat.apache.org/tomcat-7.0-doc/config/context.html **antiJARLocking** _is a subset of antiResourceLocking and therefore, to prevent duplicate work and possible issues,_ **only one of these attributes should be set to true at any one time**. – JanM Jul 02 '14 at 10:34
  • i had `antiJARLocking` set to `true`, removing the attribute from the configuration helped me (Tomcat 8) – tobijdc May 13 '15 at 09:29
  • Works well with just antiResourceLoking="true". With both, the .war file is slower to deploy and with either, it is slower to deploy than without, but saves a server restart. – J E Carter II May 22 '15 at 13:30
  • Since this is the most upvoted answer on this topic can you please mention this **little** clause: `Please note that setting this flag to true in applications that are outside the appBase for the Host (the webapps directory by default) will cause the application to be deleted on Tomcat shutdown. You probably don't want to do this, so think twice before setting antiResourceLocking=true on a webapp that's outside the appBase for its Host.` – Luca Regazzi Apr 23 '18 at 14:08
  • On a Linux system, in addition to antiResourceLocking I had to make the webapps folder world writable. – downeyt Jun 16 '20 at 20:16
13

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.

Amith Koujalgi
  • 10,746
  • 2
  • 18
  • 22
  • 1
    This does not always work. If a jar file is locked you cannot delete the parent folder(s). Stopping the application doesn't always free that jar. Forcing a reboot of Tomcat. – cbmeeks Dec 19 '17 at 13:39
2

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.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Sumant
  • 33
  • 5
0

Run your IDE as administrator. It works for me