彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题

2年前 (2022) 程序员胖胖胖虎阿
451 0 0

tomcat版本为8.5.51

tomcat在启动时,控制台会打印出如下信息:

org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。

这是tomcat在扫描包含tld文件的jar时发现有未包含tld文件的jar。解决办法就是不让tomcat扫描jar就行了。于是度娘一通发现了一些解决翻案,第一个尝试的方案就是在tomcat根目录下的conf文件夹下的catalina.properties(记得备份这个文件)中,找到tomcat.util.scan.StandardJarScanFilter.jarsToSkip彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题并修改为如下配置:

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

即下图:

彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题

 然后启动tomcat,发现控制台真的没有提示信息了,心中大喜。

但是,你以为这样就结束了?图样图森破……

当你访jstl标签时,就会出现以下界面:

彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题

无法解析 uri:[http://java.sun.com/jsp/jstl/core]

严重: Servlet.service() for servlet [jsp] in context with path [] threw exception [xxx.jsp (行.: [4], 列: [0]) 无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]] with root cause
org.apache.jasper.JasperException: xxx.jsp (行.: [4], 列: [0]) 无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]

有兴趣了解原因的可以参看这篇文章https://www.jianshu.com/p/18a75344b9f9彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题https://www.jianshu.com/p/18a75344b9f9

那么继续度娘吧,在看到了这篇文章后http://t.csdn.cn/uf37F,需要先把开始设置的tomcat.util.scan.StandardJarScanFilter.jarsToSkip还原!!!按照文章步骤进行设置,尝试了多次,并没有发现日志中出现扫描jar的信息。

后来看到这篇文章日志记录-如何修复JSP编译器警告:扫描了一个JAR中的TLD,但其中不包含TLD? - ITranslater

在第二个回答中说是需要在conf/logging.properties中添加以下代码

org.apache.jasper.servlet.TldScanner.level = FINE

彻底解决tomcat控制台提示至少有一个JAR被扫描用于TLD但尚未包含TLD的问题

 并不是org.apache.jasper.compiler.TldLocationsCache.level = FINE。按照文章说的设置之后,清除下以下两个文件夹conf/Catalina和work目录,重启tomcat。然后找到tomcat根目录下的logs文件夹中的catalina开头的log文件(tomcat控制台也有打印),打开后你会发现有以下一堆的内容

org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/commons-net-3.1.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/ridl-3.2.1.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/javassist-3.15.0-GA.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan TLD files were found in JAR [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/CKFinder-updateByAlexander-2.4.jar].                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/codegenerate-3.4.6.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/core-3.2.1.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/aopalliance-1.0.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/weixin-java-miniapp-4.2.0.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/commons-validator-1.3.1.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/postgresql-9.1-903.jdbc4.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/xstream-1.4.10.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/fastjson-1.1.37.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/jodconverter-3.0-beta-4.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/freemarker-2.3.19.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/guava-16.0.1.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/E:/webserver/tomcat-8.5.51-gts/webapps/ROOT/gts-web/WEB-INF/lib/poi-3.9.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

含有No TLD files were found的jar就是没扫描到tld的jar,需要把这些jar追加到tomcat.util.scan.StandardJarScanFilter.jarsToSkip后面。那么如何改为模糊匹配jar呢?简单写了一个方法仅供参考,特殊的jar需要手动修改一下,添加之后你会发现tomcat启动时间缩短了一些:

 public void readCatalina() throws IOException {
        //修改为自己的文件路径
        String filePath = "E:\\webserver\\tomcat-8.5.51-gts\\logs\\catalina.log";
        FileReader fr = new FileReader(filePath);
        BufferedReader bf = new BufferedReader(fr);
        String tempStr = "";
        List<String> list = new ArrayList<>();
        while ((tempStr = bf.readLine()) != null) {
            if (tempStr.indexOf("No TLD files were found in") > -1&&tempStr.indexOf(". Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.")>-1) {
                //根据项目的位置修改此处
                String weblib = "gts-web/WEB-INF/lib/";
                int start = tempStr.indexOf(weblib)+weblib.length();
                int end = tempStr.indexOf("]. Consider adding the JAR to the tomcat.util");
                String jar = tempStr.substring(start,end);
                list.add(jar);
            }
        }
        bf.close();
        fr.close();
        list.sort(Comparator.naturalOrder());
        for (String jarName : list) {
            String replaceAll = jarName.replaceAll("\\d+(.\\d+){0,2}", "*");
            System.out.println(replaceAll+",\\");
        }
    }

相关文章

暂无评论

暂无评论...