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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Disable Tomcat TLD Scanning for Faster Startup

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:

&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;Context processTlds="false"&gt; &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt; &lt;/Context&gt;

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:

&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;Context processTlds="false"&gt; &lt;JarScanner className="com.alipay.sofa.runtime.test.patch.tomcat.NullJarScanner"/&gt; &lt;/Context&gt;

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaServletTomcatTLD
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.