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.

5
  • You are definitely missing something. Recheck your java version. Check on command prompt : java -version and javac -version Mar 22, 2013 at 10:06
  • 5
    Maybe a dependency needs Java 1.7
    – Adrian
    Mar 22, 2013 at 10:07
  • 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.
    – Pieter-Jan
    Mar 22, 2013 at 10:07
  • 3
    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.
    – Pieter-Jan
    Mar 22, 2013 at 10:12
  • 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!
    – ddavison
    Nov 5, 2014 at 20:22

2 Answers 2

44

Probably you have a dependency that needs Java 1.7

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.

3
  • 7
    Yep it was Jetty 9. I can't upgrade to JDK 7 but I downgraded to Jetty 8 which does the job as well.
    – Pieter-Jan
    Mar 22, 2013 at 10:14
  • How did you downgrade the Jetty version?
    – m.dorian
    Oct 19, 2015 at 6:43
  • @m.dorian by using earlier versions of jetty Apr 28, 2016 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.