Is it possible to turn off taglib scanning in Tomcat?

浪子不回头ぞ 提交于 2019-12-06 01:52:35

问题


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?


回答1:


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.




回答2:


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




回答3:


On Tomcat 8 it can be solved by adding the META-INF\context.xml 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




回答4:


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".



来源:https://stackoverflow.com/questions/1489665/is-it-possible-to-turn-off-taglib-scanning-in-tomcat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!