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

4

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 ?

Megohm answered 14/2, 2013 at 10:57 Comment(1)
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.Knutson
H
135

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'

Hawse answered 15/2, 2013 at 16:54 Comment(7)
Does it only occur in Windows? Tomcat is based on Java, and I'm seeing similar problems on Ubuntu with Tomcat.Crappie
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.Hawse
From 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.Chickie
i had antiJARLocking set to true, removing the attribute from the configuration helped me (Tomcat 8)Vespiary
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.Decretory
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.Garrotte
On a Linux system, in addition to antiResourceLocking I had to make the webapps folder world writable.Labanna
A
12

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.

Anthesis answered 15/2, 2013 at 15:18 Comment(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.Onomatology
J
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.

Juryman answered 25/11, 2015 at 13:3 Comment(0)
C
-1

Run your IDE as administrator. It works for me

Claustral answered 15/9, 2020 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.