gpt4 book ai didi

jersey - java.lang.IllegalArgumentException jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java :170)

转载 作者:行者123 更新时间:2023-12-02 02:01:01 26 4
gpt4 key购买 nike

我正在 eclipse 中使用 Tomcat 7.0 + Maven + Java EE + JDK 10.0.2 创建 api Rest,并收到此错误:

错误:

HTTP Status 500 - Servlet.init() for servlet api threw exception

type Exception report

message Servlet.init() for servlet api threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception javax.servlet.ServletException: Servlet.init() for servlet api threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) java.base/java.lang.Thread.run(Thread.java:844)

root cause java.lang.IllegalArgumentException jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:170) jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:153) jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:424) com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner$2.f(WebAppResourcesScanner.java:104) com.sun.jersey.core.util.Closing.f(Closing.java:71) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:102) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:89) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:89) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:89) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:89) com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:79) com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) com.sun.jersey.api.core.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102) com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:89) com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:74) com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:668) com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:435) com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:602) com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87) com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:699) com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674) com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) java.base/java.lang.Thread.run(Thread.java:844)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Apache Tomcat/7.0.47

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>api</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>api</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

pom.xml

 <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>
<groupId>api</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19.4</version>
</dependency>
</dependencies>
</project>

最佳答案

经过一番挖掘,我发现 IllegalArgumentException 是由 Jersey 重新打包的 ASM 库引发的。

我不能确定我的版本是否正确,但在第 170 行,代码如下:

    // checks the class version
// added "support" for java 9 compiled classes
if (readShort(off + 6) > Opcodes.V9) {
throw new IllegalArgumentException();
}

代码正在检查它尝试读取的类的类文件版本号,如果版本太新,则抛出 IllegalArgumentException

简而言之,您正在尝试使用一些使用 Java 编译器编译的 Java 类,而该编译器对于 ASM 库来说太新了:

  • 使用较旧的 JDK 或将 -target 版本设置为较旧的版本。
  • 或者,查找/安装经过您正在构建的 Java 版本认证的 Jersey 版本。
<小时/>

令我感到奇怪的一件事是,您对 POM 文件中的旧版本“asm”有明确的依赖。但是,堆栈跟踪表明您没有使用该版本。

关于jersey - java.lang.IllegalArgumentException jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java :170),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51575703/

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