Sunday, January 17, 2010

Apache Tomcat jar locking issue.

This is a log of an issue that I faced during my experiments with deploying web applications that had dependencies on jar files in Tomcat.

At the time of writing this post, I am using a Windows XP machine, and Apache Tomcat 6.0. The IDE that I use for development is Netbeans 6.1.

The problem that I was facing was that when I deploy a web application on Tomcat from the IDE or from the Tomcat manager console, certain jar files in the lib directory of my application get locked. This happened when I tried to deploy an application that referenced a hibernate jar files and struts 2 jar files.

I came to know that they were locked when I tried to use the "Clean and Build" feature of Netbeans. My system was unable to delete certain jar files, and hence a complete clean and build was not possible until I stopped my Tomcat server. Even manual deletion of the files was not possible without server restart.

Well, I know that I could have used the unlokcer tool for windows which is a freeware to unlock my jar files, but since this does not seem to be a trivial issue, I expected a better solution.

Then after searching the web for a while, I came to know that the problem mainly persists in windows machines that use Tomcat.

Fortunately, Tomcat 6 as a feature that enables you to provide information specific to your web application in the context.xml wherein you can explicitly specify that the jar files used by your web application are not locked by Tomcat.

So, here is a sample context.xml that can be used to resolve this issue.






The path attribute is mandatory. set it to the name of the root of your web application.

To make this work for you, follow these steps.

  • Undeploy your webapp.
  • Restart the server.
  • Add the antiJARLocking and antiResourceLocking attributes to your context.xml file as shown above.
  • Deploy your application.
No more locking problems. You can now use the clean and build feature of your ide without any more hassles.

I have no idea if there is a fix for the locking issue in previous versions of Tomcat or if this issue happens in all windows machines. But this simple configuration did the trick for me. And I hope it does works for you as well.


Signing Off
Ryan

No comments: