Tomcat 7 slow start metadata-complete="true" web.xml
Solution 1
The metadata-complete didn't resolve my startup time issues either. The problem is that tomcat scans multiple (almost all jars) at startup for annotations and tld files. Of course, not all jars contains tld files and annotations. To improve your startup times you can exclude these jars. Something like the following should do the trick: Adjust conf/catalina.properties:
org.apache.catalina.startup.ContextConfig.jarsToSkip=*.jar
# Additional JARs (over and above the default JARs listed above) to skip when
# scanning for TLDs. The list must be a comma separated list of JAR file names.
# The following list will make sure stuff like jstl and spring-webmvc.jar etc which contain tld files are included
org.apache.catalina.startup.TldConfig.jarsToSkip=a*.jar,b*.jar,c*.jar,d*.jar,e*.jar,f*.jar,g*.jar,h*.jar,i*.jar,jc*.jar, jd*.jar, je*.jar, jl*.jar, jo*.jar, JO*.jar, jr*.jar, jso*.jar, jsr*.jar, jts*.jar,k*.jar,l*.jar,m*.jar,n*.jar,o*.jar,p*.jar,q*.jar,r*.jar,spring-a*.jar, spring-c*.jar, spring-e*.jar, spring-j*.jar, spring-s*.jar, spring-test*.jar, stax*.jar, st*.jar, t*.jar,u*.jar,v*.jar,w*.jar,x*.jar,y*.jar,z*.jar
Solution 2
For those who might still encounter this issue like me (while migrating to Java 8 and from Spring 3.0 to 3.2), note that you will also run into the issue if any jar you use contains a web-fragment.xml
(like spring-web).
To avoid this, you should also specify an empty absolute-ordering
in your web.xml
(according to SPRING-10196 and Tomcat's HowTo/FasterStartUp):
<absolute-ordering/>
(also make sure you are specifying servlet 3.0 in your web.xml)
Also, if you are using an old version of Tomcat, an empty absolute-ordering
will not work due to bug 54262. To fix this, use a dummy fragment name:
<absolute-ordering>
<!-- Due to a bug in Tomcat 7.0.29, an empty absolute-ordering does not prevent the annotation scanning.
Adding a dummy fragment name does the trick.
see proposed workaround in https://bz.apache.org/bugzilla/show_bug.cgi?id=54262#c0 -->
<name>dummy</name>
</absolute-ordering>
If nothing works, consider the jarsToSkip
solution proposed by @Prashant, but this is more annoying since it requires to modify the Tomcat configuration in all your environments.
(Since I am using an old version of Tomcat on Java 8, the annotation processing is completely broken for me, with lots of exceptions occurring at startup)
chiperortiz
Java Lover I'm from Venezuela. Rock 'n' Roll fan by 23 years. MLB Major League Baseball fan by 21 years... In love with Java 8 and JRebel.
Updated on June 04, 2022Comments
-
chiperortiz almost 2 years
i have migrated to Tomcat 7[7.0.4.1] in the past a startUp takes between 5 or 7 seconds now takes 30 seconds i have read on other post metadata-complete="true" set in the web.xml solves the trick but seems not solved in my case i have added
metadata-complete="true"
inWEB-INF/web.xml
and intomcat/conf/web.xml
neither seems to work.here is the code for
tomcat/conf/web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true" version="3.0">
here is the code for
WEB-INF/web.xml
<web-app metadata-complete="true" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
the deploying is being sucessfully here is the trace tomcat is printing.
INFO: Starting Servlet Engine: Apache Tomcat/7.0.41 jul 22, 2013 4:33:08 PM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath
in this sentence is taking over 30 seconds..
INFO: Starting Servlet Engine: Apache Tomcat/7.0.41
my questions are:
what i am doing wrong??
how can i see is metadata-complete is setting to true i am reading in others web-site this can be made checking the flag in
isMetadataComplete()
but my question is where or how can i call this method??
we are using [Spring,Hibernate,ZK] in out project.
-
chiperortiz over 10 yearssorry by question how can i know which jars contains TLD and annotations?? we use spring, hibernate,ehcache and ZK.
-
Prashant Saraswat over 10 yearsIt depends upon which tags you are using. Most people would use only jstl and spring form tags. In such cases, what I suggested is sufficient. You may want to look at your JSP files to see if you are using any other tags. thx.
-
Ramesh PVK almost 9 yearsScanning for TLD files is not new. It's there since beginning. That should not be a reason because it was faster in older versions of tomcat.