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

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

问题描述

我在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.

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

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