Thursday, October 8, 2009

Tomcat Locked Resources

So I spent a few minutes the other day setting up a nice ant task to deploy my war file to Tomcat automatically. It worked the first time, but not the second time - because Tomcat still had some jars locked down in the WEB-INF directory. Today I finally figured out a solution to the problem. One can add this the following attributes to the META-INF/context.xml file to solve the trouble...

antiJARLocking
If true, the Tomcat classloader will take extra measures to avoid JAR file locking when resources are accessed inside JARs through URLs. This will impact startup time of applications, but could prove to be useful on platforms or configurations where file locking can occur. If not specified, the default value is false.

antiResourceLocking
If true, Tomcat will prevent any file locking. This will significantly impact startup time of applications, but allows full webapp hot deploy and undeploy on platforms or configurations where file locking can occur. If not specified, the default value is false.
Please note that setting this to true has some side effects, including the disabling of JSP reloading in a running server: see Bugzilla 37668.
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.

the above from http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

In a minimal sense:
<Context antiJARLocking="true" antiResourceLocking="true" />

is all you need.

No comments:

Post a Comment