简体   繁体   中英

How to disable Tomcat JARScanner

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

According todocumentation 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.

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

According todocumentation 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.

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

According todocumentation 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.

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);
        }
    };
}

This is what I did for Spring Boot.

Basically, append a new ignored jar file to the existing list of jars to ignore. This way, you don't totally disable the scanner, affecting who knows what else.

@Configuration
public class Config {

    @Bean
    public ServletWebServerFactory servletContainer() {
        return new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                // db2 puts a ref to pdq.jar in the manifest, and tomcat then tries to find it, but it doesn't exist.
                // The jar isn't needed, so we just disable looking for it. You could also remove it from the manifest,
                // but that prob needs to be done after the build process.
                JarScanFilter jarScanFilter = context.getJarScanner().getJarScanFilter();
                if (jarScanFilter instanceof StandardJarScanFilter) {
                    StandardJarScanFilter filter = (StandardJarScanFilter) jarScanFilter;
                    String oldTldSkip = filter.getTldSkip();
                    String newTldSkip = oldTldSkip == null || oldTldSkip.trim().isEmpty() ? "pdq.jar" : oldTldSkip + ",pdq.jar";
                    filter.setTldSkip(newTldSkip);
                } else {
                    logger.warn("Unable to disable the tomcat jar scanner for pdq.jar. You may see a FileNotFound exception complaining of not finding a db2 pdq.jar file. You can probably ignore the error. Ref: https://stackoverflow.com/questions/11656596/how-to-disable-tomcat-jarscanner");
                }
            }
        };
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM