【问题标题】:How to fix "JARs that were scanned but no TLDs were found in them " in Tomcat 9.0.0M10如何在 Tomcat 9.0.0M10 中修复“已扫描但未在其中找到 TLD 的 JAR”
【发布时间】:2017-03-05 09:17:20
【问题描述】:

我是 Java EE 的新手,正在尝试使用 ServletContextListener 并且侦听器工作是连接到数据库 bla bla 。当我尝试启动服务器(Tomcat 9)时,它卡住了:

“信息:至少有一个 JAR 已扫描 TLD,但未包含 TLD。 启用此记录器的调试日志记录以获取完整的 JAR 列表 已扫描但未在其中找到 TLD。跳过不需要的 JAR 在扫描期间可以提高启动时间和 JSP 编译时间。”

所以我更改了“日志记录属性文件”中的一些属性,如下所示:

    # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter


############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = FINE
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = FINE
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = FINE
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler

# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE

# To see debug messages in TldLocationsCache, uncomment the following line:
org.apache.jasper.compiler.TldLocationsCache.level = FINE
org.apache.jasper.servlet.TldScanner.level = FINE

# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE

# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE

所有答案都可以接受。谢谢大家。

【问题讨论】:

标签: java tomcat server


【解决方案1】:

更改 conf\context.xml 文件

<Context>
    <!-- only if you do not use jsp tag -->
    <JarScanner>
        <JarScanFilter defaultPluggabilityScan="false" defaultTldScan="false"/>
    </JarScanner>
</Context>

见:https://tomcat.apache.org/tomcat-9.0-doc/config/jar-scan-filter.html

【讨论】:

    【解决方案2】:

    我解决了同样的问题.. 我认为这有权限问题,因此需要为 webapps/project 文件夹提供完全访问权限。

    【讨论】:

    • 请改写您的问题,而不是猜测(“我认为...”)。就目前而言,这更像是一条评论。
    【解决方案3】:

    不需要将日志记录设置为 FINE、FINEST 或 ALL 来查找所有要排除的 jar。

    这是一个脚本,用于查找所有不包含 TLD 的 jar(更改 TOMCAT_HOME 变量以匹配您的安装)并在表单上输出一个列表

    jar1.jar,\
    jar2.jar,\
    ...
    

    可以粘贴到 catalina.properties 中(省略最后一个 ',\'):

    #!/bin/sh
    TOMCAT_HOME=/opt/tomcat
    for i in `find $TOMCAT_HOME -follow -name "*jar"`
    do
        jar tvf $i | grep -i tld > /dev/null
        if [ $? -ne 0 ]; then
            echo "$(basename $i),\\"
        fi
    done
    

    但是,如果我被正确告知,tomcat 9 有可能通过更改(在 catalina.properties 中)来排除所有 jar:

    tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
    

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

    (注释掉下面行中的列表)然后通过更改覆盖包含 TLD 的 jar 的决定:

    tomcat.util.scan.StandardJarScanFilter.jarsToScan=\
    log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar
    

    并添加通过修改上述脚本获得的列表以列出确实包含 TLD 的 jar:

    #!/bin/sh
    TOMCAT_HOME=/opt/tomcat
    for i in `find $TOMCAT_HOME -follow -name "*jar"`
    do
        jar tvf $i | grep -i tld > /dev/null
        if [ $? -eq 0 ]; then
            echo "$(basename $i),\\"
        fi
    done
    

    【讨论】:

    • 请注意,如果任何 jar 包含包含字母“tld”的文件,但实际上不是 .tld 文件,则这些 jar 也被视为包含 .tld 文件。
    【解决方案4】:

    这不是 tomcat 中的错误或任何类型的问题。 Tomcat 只是通知您存在不包含 TLD 的 jar,您可以将它们添加到扫描仪的跳过列表中以提高启动性能。所以你有两个选择:

    1. 您可以放心地忽略该提示。但是,如果它惹恼了您,您可以将该特定记录器设置为更高的记录级别,从而防止 tomcat 记录它。只需将org.apache.jasper.servlet.TldScanner.level = SEVERE 添加到logging.properties 的末尾即可。

    2. 启用调试日志以使 tomcat 列出这些 jar 并将它们添加到跳过列表中。设置:

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

    并将打印的 jar 名称(不包括路径)添加到 tomcat_dir/conf/catalina.properties 中的tomcat.util.scan.StandardJarScanFilter.jarsToSkip=...

    【讨论】:

    • 谢谢你的解释,我会尽力通知你的。
    • 像这样:" tomcat.util.scan.StandardJarScanFilter.jarsToSkip= 1org.apache.jasper.servlet.TldScanner,2org.apache.jasper.compiler.TldLocationsCache" ?
    • 对不起这样的:“org.apache.jasper.compiler.TldLocationsCache.jar,org.apache.jasper.servlet.TldScanner.jar”
    • 不,您必须列出“要跳过的罐子”,没有 etomcat 类。首先,您需要启用调试日志以找出 jar 的名称,然后将它们作为逗号分隔列表添加到 tomcat.util.scan.StandardJarScanFilter.jarsToSkip= 属性
    • 现在我理解得更好了。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2012-12-31
    • 2011-10-10
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 2013-08-17
    相关资源
    最近更新 更多