We're running Tomcat8 on Windows and redeploying applications sometimes fails due to Windows locking jars of properties.
I found this documentation saying that you have to add the AntiResourceLocking
-attribute to a Context
-element: Apache Tomcat 8 Configuration Reference
All our servers are built using scripts so doing this in the server.xml
should not be a problem (if it works?):
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context antiResourceLocking="true"></Context>
</Host>
</Engine>
When the server restarts Tomcat prints the following errors and we have no real clue as to what is wrong:
Failed to initialize component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]]
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]]
Caused by: java.lang.NullPointerException
at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:6233)
Has anyone done this before? Am I missing something?
What you are missing is the difference between conf/server.xml
and conf/context.xml
.
When you add a <Context .../>
element to conf/server.xml
you are defining an individual context (web application). This is equivalent to defining a <Context .../>
element in CATALINA_BASE/conf/<engine-name>/<host-name>/<context-name>.xml
or in a /META-INF/context.xml
file packaged as part of the web application.
The <Context .../>
element in conf/context.xml
defines defaults for all contexts (web applications).
The single Context element you have adding in conf/server.xml
is failing because you haven't specified a path.
If you really want to enable anti-resource locking for all web applications then you need to add antiResourceLocking="true" as an attribute to the <Context .../>
element in CATALINA_BASE/conf/context.xml
.
As an aside, this option is only a work-around for resource leaks in your web application. You might want to consider taking the time to fix those resource leaks.
Visit http://tomcat.apache.org/tomcat-8.0-doc/config/context.html for recommended way.
You can define context.xml in META-INF/context.xml in you WAR or
you can define conf/Catalina/localhost WAR_NAME.xml
To configure antiResourceLocking in xml add following tag in context.xml
<Context antiResourceLocking="true"></Context>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With