java.lang.UnsupportedClassVersionError - jdk版本

时间:2014-04-15 06:46:42

标签: java eclipse

我使用 Windows 7 平台上的 jdk 1.7.0_03 在Eclipse中开发了一个API。在其他Windows 7系统上部署时,它可以正常工作。

使用 jdk 1.6 Windows 8 系统上部署它时,它提供了以下异常:

HTTP Status 500 - Servlet.init() for servlet MediaPlayer-Backend-API threw exception

type Exception report

message Servlet.init() for servlet MediaPlayer-Backend-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 MediaPlayer-Backend-API threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)
root cause

java.lang.UnsupportedClassVersionError: favorite/api/VideoManager : Unsupported major.minor version 51.0 (unable to load class favorite.api.VideoManager)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2908)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Class.java:247)
    com.sun.jersey.core.reflection.ReflectionHelper$3.run(ReflectionHelper.java:284)
    com.sun.jersey.core.reflection.ReflectionHelper$3.run(ReflectionHelper.java:279)
    java.security.AccessController.doPrivileged(Native Method)
    com.sun.jersey.spi.scanning.AnnotationScannerListener$AnnotatedClassVisitor.getClassForName(AnnotationScannerListener.java:224)
    com.sun.jersey.spi.scanning.AnnotationScannerListener$AnnotatedClassVisitor.visitEnd(AnnotationScannerListener.java:188)
    org.objectweb.asm.ClassReader.accept(Unknown Source)
    org.objectweb.asm.ClassReader.accept(Unknown Source)
    com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
    com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
    com.sun.jersey.core.util.Closing.f(Closing.java:71)
    com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
    com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
    com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:226)
    com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:142)
    com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
    com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
    com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
    com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
    com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
    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:376)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.

Apache Tomcat/7.0.33

我提到this answer并更改了 已安装的JRE 编译器合规性 级别API Eclipse项目为 jdk 1.5.0_15

然而,在部署API时,我遇到了同样的错误。

关于什么是错误以及我如何使API与所有系统兼容的任何帮助?

3 个答案:

答案 0 :(得分:0)

您正在使用两个不同的JDK来运行该程序。 Java不向后兼容,因此您必须使用您编译的相同版本运行。

jdk 1.7.0_03

jdk 1.6

答案 1 :(得分:0)

如果您能够在JDK 1.5中编译API,则无法出现 UnsupportedClassVersionError 错误。

确保Eclipse中的编译器版本设置正确,并清理生成.class文件的目录。使用eclipse编辑器对部分或全部java文件进行一些微小的更改,并生成新的类文件,并在部署之前检查生成的类文件/ jar的时间戳。

答案 2 :(得分:0)

将eclipse java版本更改为jdk 1.7并进行编译。或者检查VideoManager.class是按哪个版本构建的?获取该版本并使用该版本构建项目。