Tomcat 7 + log4j-api-2.11.1.jar 中的注释 [英] Tomcat 7 + Annotations in log4j-api-2.11.1.jar

查看:60
本文介绍了Tomcat 7 + log4j-api-2.11.1.jar 中的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动 war 文件时从 tomcat 得到这个异常:

I get this exception from tomcat upon startup of the war file:

Unable to process Jar entry [META-INF/versions/9/module-info.class] from Jar [jar:file:/C:/tomcat/apache-tomcat-7.0.61/webapps/monitormonitor/WEB-INF/lib/log4j-api-2.11.1.jar!/] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in
constant pool: 19
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:97)

我尝试将 pom.xml 中的 log4j 切换到旧版本,但失败了,它仍然扫描 log4j-api-2.11.1.jar.我在 tomcats web.xml 中添加了 metadata-complete="true" 但这并没有改变错误.

I tried to switch the log4j to an older version in the pom.xml, but failed, it still scans log4j-api-2.11.1.jar. I added metadata-complete="true" to the tomcats web.xml but this didn't change the error.

我在 stackoverflow 上阅读了其他页面,但没有解决我的问题:

I read other pages on stackoverflow, but it didn't resolve my problem:

Tomcat 7 和 Java 8 兼容性问题

常量池中的字节标记无效:19 错误消息

后者似乎有一个很好的答案,但我不明白如何从注释扫描中排除文件,我也不知道排除文件如何影响 Web 应用程序的功能.

The latter seems to have a good answer, but I don't understand how to exclude files from annotation scanning, and I also do not know how excluding files affects the functionality of the web application.

请找到我的 pom.xml 附件.它包括我在注释掉的版本中修复此问题的一些尝试.

Please find attached my pom.xml. It includes some of my attempts to fix this in a commented out version.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xxx</groupId>
    <artifactId>monitormonitor</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>monitormonitor</name>
    <description>Web Service Monitoring project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <packaging>war</packaging>

    <dependencies>
        <!-- added recent version of icu4j and log4j for invalid byte tag error -->
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <!-- changed version vs. ClassFormatException: Invalid byte tag in constant pool: 19 -->
            <!--<version>2.11.1</version>-->
            <version>2.7</version>
            <!--<scope>provided</scope>-->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>provided</scope><!-- changed -->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <!-- duplicate
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        -->
        <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        -->
        <!-- added recent version of icu4j and log4j for invalid byte tag error -->
        <!-- https://mvnrepository.com/artifact/com.ibm.icu/icu4j -->
        <!--<dependency>
            <groupId>com.ibm.icu</groupId>
            <artifactId>icu4j</artifactId>
            <version>63.1</version>
        </dependency>
        -->

        <!-- added this dependency vs. ClassFormatException: Invalid byte tag in constant pool: 19 -->
        <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools -->
        <!--             <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>1.9.1</version>
                    </dependency>
        -->
                    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
        <!--         <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>1.9.1</version>
                    </dependency>
        -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我更喜欢不需要升级 tomcat 的解决方案.我的tomcat版本是apache-tomcat-7.0.61.

I would prefer a solution where I don't have to upgrade the tomcat. My tomcat version is apache-tomcat-7.0.61.

推荐答案

降级正确的 log4j 包似乎解决了问题:

Downgrading the right log4j package seems to have solved the problem:

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <!-- changed version vs. ClassFormatException: Invalid byte tag in constant pool: 19 -->
        <!--<version>2.11.1</version>-->
        <version>2.7</version>
        <!--<scope>provided</scope>-->
    </dependency>

spring boot 应用程序仍然无法正常启动,但这是一个不同的问题.

The spring boot app still doesn't start up properly, but that is a different issue.

这篇关于Tomcat 7 + log4j-api-2.11.1.jar 中的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆