Unsupported major.minor version 51.0 but everything is set to JDK 1.6
Asked Answered
P

2

33

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.

Possum answered 22/3, 2013 at 10:2 Comment(5)
You are definitely missing something. Recheck your java version. Check on command prompt : java -version and javac -versionDebutante
Maybe a dependency needs Java 1.7Talcahuano
java -version and javac -version both return 1.6.0_38, but I don't actually compile using the command prompt. I only use it to run my app. I'm compiling using Maven, and there I use the maven plugn.Possum
Adrian, you're a life saver. My pom specified the wrong version of Jetty. Jetty 9 requires JDK 1.7, please post your response as an answer so I can give you proper credit.Possum
I use IntelliJ 14, and I don't include a compiler plugin. I fixed this issue by removing the target/ directory. After that, worked just fine!Territus
T
44

Probably you have a dependency that needs Java 1.7

Talcahuano answered 22/3, 2013 at 10:32 Comment(0)
G
14

You're probably using a dependency which requires Java SE 7.

If this is the case either upgrade to Java SE 7 (recommended if you're using the JRE from Oracle without support contract, as Java SE 6 reached End of Life in February) or replace this dependency.

Ginnygino answered 22/3, 2013 at 10:11 Comment(3)
Yep it was Jetty 9. I can't upgrade to JDK 7 but I downgraded to Jetty 8 which does the job as well.Possum
How did you downgrade the Jetty version?Commandant
@Commandant by using earlier versions of jettyNatelson

© 2022 - 2024 — McMap. All rights reserved.