How to Disable Tomcat TLD Scanning for Faster Startup
This guide explains why and how to turn off Tomcat's TLD scanning during startup, shows the necessary context.xml changes, addresses a Tomcat 6 pitfall with a custom JarScanner workaround, and notes that Tomcat 7 handles the setting correctly.
Background
Tomcat, as an implementation of the Servlet specification, scans JAR files for .tld files and loads the defined tag libraries when the application starts. When developers use template engines such as Velocity instead of JSP, disabling this scan can speed up startup.
Method
According to Tomcat's configuration documentation, the processTlds attribute of <Context> controls whether TLDs are processed on startup. Setting it to false disables the scan. To apply this to all applications, edit conf/context.xml as follows:
<?xml version='1.0' encoding='utf-8'?> <Context processTlds="false"> <WatchedResource>WEB-INF/web.xml</WatchedResource> </Context>
Pitfall
In Tomcat 6 the setting does not take effect because the StandardContext initialization processes TLDs before the lifecycle event where the configuration is applied. The relevant code is:
if (processTlds) { this.addLifecycleListener(new TldConfig()); } super.init(); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(INIT_EVENT, null);
Since processTlds is evaluated before the INIT_EVENT, the configuration is ignored.
Workaround: define an empty JarScanner in context.xml to prevent TLD scanning:
<?xml version='1.0' encoding='utf-8'?> <Context processTlds="false"> <JarScanner className="com.alipay.sofa.runtime.test.patch.tomcat.NullJarScanner"/> </Context>
The NullJarScanner implementation simply does nothing:
package com.alipay.sofa.runtime.test.patch.tomcat; import org.apache.tomcat.JarScanner; import org.apache.tomcat.JarScannerCallback; import javax.servlet.ServletContext; import java.util.Set; public class NullJarScanner implements JarScanner { @Override public void scan(ServletContext context, ClassLoader classloader, JarScannerCallback callback, Set<String> jarsToSkip) { // Do nothing at all. } }
Tomcat 7 does not exhibit this issue; setting processTlds="false" works out of the box.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
