问题:java.lang.UnsupportedClassVersionError:org/glassfish/jersey/servlet/ServletContainer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33010871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Issue: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/ServletContainer
提问by Kaushi
I have written a RESTful web services. Below is my maven dependencies.
我编写了一个 RESTful Web 服务。下面是我的 Maven 依赖项。
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.12.Final</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
Below is my web.xml
下面是我的 web.xml
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have pointed my JRE to jre6 and the compiler version to 1.6 in my eclipse. Rest Web Services are working perfectly.
在我的 Eclipse 中,我已将 JRE 指向 jre6,将编译器版本指向 1.6。Rest Web 服务运行良好。
I export as WAR and put the WAR file in webapps folder of tomcat and deploy. It is getting deployed. Issue is coming when I invoke the Web service, it is throwing the following error.
我导出为 WAR 并将 WAR 文件放在 tomcat 的 webapps 文件夹中并部署。它正在部署。当我调用 Web 服务时出现问题,它抛出以下错误。
java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/ServletContainer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.ServletContainer)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2961)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
Tomcat version is 7 and JDK is 1.6 and JRE is 6. I understand that error is coming because of version problem.
Tomcat 版本是 7,JDK 是 1.6,JRE 是 6。我知道错误是因为版本问题。
How can I fix this? Anyone pls help me with this.
我怎样才能解决这个问题?任何人请帮助我。
回答by Kayaman
Your jersey lib doesn't support 1.6 Java. Either see if there's a jersey build that works with 1.6, or upgrade your Java.
您的球衣库不支持 1.6 Java。要么查看是否有适用于 1.6 的 jersey 版本,要么升级您的 Java。
UPDATE
更新
Java 1.6 is supported in Jersey 2.6 and below. Jersey 2.7 and later is compiled with Java 7.
Jersey 2.6 及更低版本支持 Java 1.6。Jersey 2.7 及更高版本使用 Java 7 编译。
回答by Sajan Chandran
The problem is as you know using a version of jersey jar which is compiled using Java 7 and you are running using Java 6
.
Either downgrade your Jersey version or upgrade your Java version to 7.
问题正如你所知using a version of jersey jar which is compiled using Java 7 and you are running using Java 6
。降级您的 Jersey 版本或将您的 Java 版本升级到 7。
Unsupported major.minor version 51.0
Unsupported major.minor version 51.0
J2SE 8 = 52, J2SE 7 = 51, J2SE 6.0 = 50, J2SE 5.0 = 49, JDK 1.4 = 48, JDK 1.3 = 47, JDK 1.2 = 46, JDK 1.1 = 45
J2SE 8 = 52,J2SE 7 = 51,J2SE 6.0 = 50,J2SE 5.0 = 49,JDK 1.4 = 48,JDK 1.3 = 47,JDK 1.2 = 46,JDK 1.1 = 45
回答by Stultuske
This is because you compiled it using a higher version of Java. For instance, compile Java 7 code which has a switch on Strings, then try to run that application on JRE 6 (which doesn't support switch on Strings) and this is what you get.
这是因为您使用更高版本的 Java 编译它。例如,编译具有字符串开关的 Java 7 代码,然后尝试在 JRE 6(不支持字符串开关)上运行该应用程序,这就是您得到的。
Re-compile your code in Java 6, or run the code using the version of Java in which you compiled it.
在 Java 6 中重新编译您的代码,或使用您编译它的 Java 版本运行代码。