Is it possible to turn off taglib scanning in Tomcat?
Asked Answered
M

4

8

On startup, Tomcat recursively scans the WEB-INF directories for TLD (Tag Library Descriptor) files. As a result, if a webapp has a lot of files under that directory, it slows down the startup process. Does anyone know if there is a way in that situation to turn off scanning completely, or at least provide a filter to narrow the search?

Misdeem answered 28/9, 2009 at 22:18 Comment(4)
Is there a way to assign just the specific jars you want to scan?Mikaelamikal
But if you remove some jars, they will not be computed correctly, will they?Aerogram
@Aerogram I don't quite understand your question? Were you meaning to point out that if you do this, no tag library descriptors will be found? If so, that wasn't (and still isn't) a problem for my case because I wasn't using JSPs.Misdeem
I was assuming you used JSP pages, so I said that if you turn off scanning completely I suppose you can't build it if requires some specific JARs to proceed with a clean Startup. If you weren't using JARs, probably it's not the case, is it?Aerogram
I
14

You can add processTlds attributes in the context,

  <Context processTlds="false" ... />

However, your TLDs defined in the JAR file wouldn't work without scanning the JARs. You have to define all TLDs in WEB-INF.

Immigration answered 28/9, 2009 at 23:46 Comment(3)
Seems to be a Tomcat 7 attribute.Gabbey
Do you know why I get this error? "Setting property 'processTlds' to 'false' did not find a matching property." Is it because I added the property in the global Tomcat /conf/context.xml ?Elfland
The same message ('no matching property') appears even after I removed the property from /conf/context.xml and added it to META-INF/context.xml. Is this property not supported in Tomcat 8.5 ?Elfland
F
13

Since Tomcat 8 it can be solved by adding the META-INF/context.xml file with the configuration seen below to your WAR file. No need to change the global Tomcat configuration.

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <JarScanner>
        <JarScanFilter tldSkip="*.*"/>
    </JarScanner>
</Context>

The relevant documentation is available here: http://tomcat.apache.org/tomcat-8.0-doc/config/jar-scan-filter.html

Forgo answered 21/2, 2017 at 11:28 Comment(0)
B
10

I was puzzled by the same problem. Looking into source code of Tomcat 7.0.40, it is not possible to avoid jars scanning by setting 'processTlds=false', they will still be scanned for web fragments (ContextConfig.processJarsForWebFragments()).

There are 2 options remaining:

Set property in TOMCAT_HOME/conf/catalina.properties

org.apache.catalina.startup.ContextConfig.jarsToSkip=*.jar

Replace StandardJarScanner by your own implementation, for example empty one and refer to it from my.war/META-INF/context.xml:

<Context processTlds="false">
    <JarScanner className="org.my.tomcat.NullJarScanner"/>
</Context>

In latter case you'll need to make sure that NullJarScanner class is available in tomcat's lib directory, not your .war

Bantamweight answered 28/6, 2013 at 20:5 Comment(0)
T
1

As an alternative (if you still prefer to scan some JARs) you could append new values to "tomcat.util.scan.DefaultJarScanner.jarsToSkip" property in "{TOMCAT_HOME}/conf/catalina.properties".

Tertius answered 12/4, 2012 at 17:42 Comment(2)
That's new in Tomcat 7, right? In my case, I'm still on Tomcat 6, but for Tomcat 7 users that looks like a good option.Misdeem
Yes. Not applicable to Tomcat 6. Property appears in Tomcat 7.Tertius

© 2022 - 2024 — McMap. All rights reserved.