问题
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)
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.
I read other pages on stackoverflow, but it didn't resolve my problem:
Tomcat 7 and Java 8 compatibility issue
Invalid byte tag in constant pool: 19 error message
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.
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>
I would prefer a solution where I don't have to upgrade the tomcat. My tomcat version is apache-tomcat-7.0.61.
回答1:
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>
The spring boot app still doesn't start up properly, but that is a different issue.
来源:https://stackoverflow.com/questions/54578459/tomcat-7-annotations-in-log4j-api-2-11-1-jar