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
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...
So I made sure that everything is set to version 1.6 :
system.properties file in the root contains
java.runtime.version=1.6
Added the maven property
<java.version>1.6</java.version>
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>
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)
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.
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...
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…