Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Tomcat JARScanner

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.

like image 978
Gonzalo Gallotti Avatar asked Jul 25 '12 18:07

Gonzalo Gallotti


3 Answers

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>
like image 165
Lari Hotari Avatar answered Nov 18 '22 05:11

Lari Hotari


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

like image 24
Black Avatar answered Nov 18 '22 05:11

Black


in your java app add this :

@Bean
public TomcatServletWebServerFactory tomcatServletFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(final Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
        }
    };
}
like image 1
Shaheed Avatar answered Nov 18 '22 05:11

Shaheed