java.lang.UnsupportedClassVersionError不支持的major.minor版本51.0

时间:2012-06-28 06:23:16

标签: java jdk1.6 unsupported-class-version

  

可能重复:
  unsupported major .minor version 51.0

我正在尝试构建一个应用程序,但它会产生一些错误。我的JDK版本如下:

java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

这是我的错误日志:

Buildfile: build.xml

compile:
     [echo] Compiling the service....
     [echo]   ...mkdir for classes first....
     [echo]   ...java classes next....
     [echo]   ...mkdir for generated code next....
     [echo]  ...generate stubs/skeletons next....
[wscompile] command line: wscompile -d /home/vivekray/program/MTrans/WEB-INF/classes -features:wsi,documentliteral -gen:server -keep -model /home/vivekray/program/MTrans/WEB-INF/model.gz -verbose -Xprintstacktrace /home/vivekray/program/MTrans/src/config.xml -classpath /home/vivekray/program/MTrans/WEB-INF:/home/vivekray/program/MTrans/WEB-INF/classes:/home/vivekray/program/MTrans/lib/log4j-1.2.16.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/mail.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/activation.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/jaxp-api.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/dom.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/sax.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/xalan.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/xercesImpl.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-api.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-spi.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-impl.jar:/home/vivekray/jwsdp-2.0/saaj/lib/saaj-api.jar:/home/vivekray/jwsdp-2.0/saaj/lib/saaj-impl.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/relaxngDatatype.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/xsdlib.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/jax-qname.jar:/home/vivekray/jwsdp-2.0/apache-ant/lib/ant.jar:/home/vivekray/jwsdp-2.0/fastinfoset/lib/FastInfoset.jar:/home/vivekray/Softwares/apache-tomcat-7.0.27/lib/servlet-api.jar
[wscompile] [creating model: mtransservice]
[wscompile] [creating service: Mtransservice]

BUILD FAILED
java.lang.UnsupportedClassVersionError: in/cdac/mobile/computing/mtrans/MtransService : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1146)
    at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1324)
    at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1388)
    at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1341)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1088)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getLoadableClassName(RmiUtils.java:78)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getRealName(RmiUtils.java:54)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.modelPort(RmiModeler.java:676)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildLiteralModel(RmiModeler.java:603)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildModel(RmiModeler.java:457)
    at com.sun.xml.rpc.processor.config.ModelInfo.buildModel(ModelInfo.java:88)
    at com.sun.xml.rpc.processor.Processor.runModeler(Processor.java:63)
    at com.sun.xml.rpc.tools.wscompile.CompileTool.run(CompileTool.java:714)
    at com.sun.xml.rpc.util.ToolBase.run(ToolBase.java:43)
    at com.sun.xml.rpc.tools.ant.Wscompile.execute(Wscompile.java:746)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Total time: 1 second

7 个答案:

答案 0 :(得分:254)

这些家伙告诉你为什么失败而不是如何解决它的原因。即使您有一个与您尝试使用的JVM匹配的jdk,也可能出现此问题。

项目 - >属性 - > Java编译器

启用项目特定设置。

然后选择编译器合规性级别为1.6或1.5,构建并测试您的应用程序。

现在,应该没事。

答案 1 :(得分:238)

发生

java.lang.UnsupportedClassVersionError是因为编译期间JDK较高,运行时期间JDK较低。

以下是版本列表:

Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

答案 2 :(得分:18)

第51版是Java 7,你可能使用了错误的JDK。检查JAVA_HOME。

As mentioned here, under Binary Compatibility

答案 3 :(得分:4)

这意味着您在特定JDK 下编译了类,但后来尝试在JDK的旧版本下运行它们。

答案 4 :(得分:4)

我遇到了同样的问题,当jdk 1.7用于编译时,jre 1.4用于执行。

我的解决方案是通过在现有PATH设置前添加路径名C:\ glassfish3 \ jdk7 \ bin来设置环境变量PATH。更新的值为“C:\ glassfish3 \ jdk7 \ bin; C:\ Sun \ SDK \ bin”。更新后,问题就消失了。

答案 5 :(得分:2)

确保在编译/运行时使用正确的SDK,并确保使用源/目标1.7。

答案 6 :(得分:2)

使用Maven并使用maven-compiler-plugin显式调用实际正确版本的JDK javac.exe命令,因为Maven可以运行任何版本;这也抓住了 javac中真正愚蠢的长期存在的错误,它没有发现运行时破坏类版本jar并且在编译早期java版本时缺少类/方法/属性!通过向新类,方法和属性或单独的编译器版本控制数据添加版本控制属性,可以很容易地在Java 1.5+中修复后面的部分,因此Sun和Oracle的监督是非常愚蠢的。