How to disable Tomcat JARScanner

17,247

Solution 1

You should add the JarScanner element as a child of the root Context element in the context.xml file.

I have this kind of META-INF/context.xml file in the war file for disabling the JarScanner:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <JarScanner scanClassPath="false" scanAllFiles="false" scanAllDirectories="false"/>
</Context>

Solution 2

you can disable the JarScanner globally for user-definted patterns by opeining the file at

%TOMCAT_HOME%/conf/catalina.properties

and add a filename pattern to tomcat.util.scan.StandardJarScanFilter.jarsToSkip list. For example, if you want to disable jar scanning completely you could add:

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
*.jar,\

NOTE: this may of course lead to issues if you're employing JSTL, as templates won't be found by the scanner

Share:
17,247
Gonzalo Gallotti
Author by

Gonzalo Gallotti

Updated on June 05, 2022

Comments

  • Gonzalo Gallotti
    Gonzalo Gallotti almost 2 years

    How: To disable Tomcat JARScanner?
    Why: To stop Tomcat scan every .jar in my LIB folder.

    According to documentation it says that it is possible to disable it within context.xml. But it seems to not be working. (May be I am missing something) I made an exhaustive search in forums and could not find the solution.

    This is in context.xml (not working yet):

    <JarScanner scanClassPath="false" scanAllFiles="false" scanAllDirectories="false"></JarScanner>
    

    Thanks in advance.

    • Christopher Schultz
      Christopher Schultz almost 12 years
      Please post your attempted configuration. It's hard to guess why it's not working when you don't post what you've tried.
    • Gonzalo Gallotti
      Gonzalo Gallotti over 11 years
      I've added the line i'am using in context.xml. Sorry and thanks
    • Christopher Schultz
      Christopher Schultz over 11 years
      Do you want to disable scanning of all JAR files entirely? You have no .tld files that need to be auto-discovered and you don't use any annotations?
    • Gonzalo Gallotti
      Gonzalo Gallotti over 11 years
      I removed the entry from web.xml and the issue stoped. Still wanting to disable JarScanner from Context.xml (for prototyiping purposes)
  • Stephen Ostermiller
    Stephen Ostermiller over 6 years
    Is that the global context.xml file located at /etc/tomcat8/context.xml? Can jar scanning be disabled on a web-app by web-app basis by instead placing the configuration in your web app's war file in WEB-INF/web.xml?
  • Talijanac
    Talijanac about 6 years
    It can be disabled on web-app by bassis by using application META-INF/context.xml file