不支持的major.minor版本51.0,但一切都设置为JDK 1.6 [英] Unsupported major.minor version 51.0 but everything is set to JDK 1.6
问题描述
我有一个Maven Eclipse应用程序,我正在尝试使用以下命令在命令提示符下运行:
I have a Maven Eclipse application which I'm trying to run through the command prompt using the following command:
java -cp target/classes;"target/dependency/*" com.example.Main
不幸的是,它抛出错误:
Unfortunately, it throws an error:
UnsupportedClassVersionError : unsupported major.minor version 51.0
我做了一些挖掘,发现它与在较新版本的JDK上编译的应用程序有关,而不是它运行的JRE。显然51意味着它是为1.7而构建的,但我的计算机上没有JDK 7 ...
I did some digging and found out it has something to do with the application being compiled on a JDK of a newer version, than the JRE it runs on. Apparently the 51 means it was built for 1.7, but I don't have a JDK 7 on my computer...
所以我确保一切都设置为版本1.6:
So I made sure that everything is set to version 1.6 :
root中的system.properties文件包含
system.properties file in the root contains
java.runtime.version=1.6
添加了maven属性
<java.version>1.6</java.version>
在我的pom.xml中指定了maven编译器插件
Specified the maven compiler plugin in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
我使用返回的命令java -version检查了我的java版本
I checked the version of my java using the command java -version which returned
Java version "1.6.0_38"
Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
Java HotSpot(TM) 64-bit Server VM (build 20.13-b02, mixed mode)
并更新设置maven-compiler-plugin后我的项目导致Eclipse自动将编译器级别设置为1.6,项目facet级别为1.6,并将JavaSE-1.6 jre系统库添加到我的项目中。
And an update of my project after setting the maven-compiler-plugin resulted in Eclipse automatically setting the compiler level to 1.6, the project facet level to 1.6 and adding the JavaSE-1.6 jre system library to my project.
所以我完全不知道这个JDK 1.7的来源。我从未在这台计算机上安装过JDK 1.7 ... ...
So I have absolutely no idea where this JDK 1.7 is coming from. I never installed JDK 1.7 on this computer to begin with...
另外,最初,maven-compiler-plugin不存在所以它是用1.5升构建的猜测。但我做了 mvn clean install
,然后是 mvn包
,然后在所有设置完成后再次尝试命令调整后它仍会抛出同样的错误。
Also, originally, the maven-compiler-plugin wasn't present so it was build with 1.5 I guess. But I did a mvn clean install
, then a mvn package
, and then tried the command again after all the settings were adjusted and it still throws the same error.
推荐答案
可能你有一个需要Java 1.7的依赖项
Probably you have a dependency that needs Java 1.7
这篇关于不支持的major.minor版本51.0,但一切都设置为JDK 1.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!