gpt4 book ai didi

java - Tomcat 7 + log4j-api-2.11.1.jar 中的注解

转载 作者:行者123 更新时间:2023-11-28 22:15:46 25 4
gpt4 key购买 nike

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

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)

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

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

Tomcat 7 and Java 8 compatibility issue

Invalid byte tag in constant pool: 19 error message

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

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

<?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。

最佳答案

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

    <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 应用程序仍然无法正常启动,但这是另一个问题。

关于java - Tomcat 7 + log4j-api-2.11.1.jar 中的注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54578459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com