Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0

Last updated
App Shah

Crunchify » Java and J2EE Tutorials » Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0

Recently I faced this wired exception while running my Java application on Linux environment.

java.lang.UnsupportedClassVersionError: com.crunchify.testClass :
 Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
       .........................................

The only difference I noticed in about Java Version. I compiled all code on my laptop with version 7 and Linux had version 6. java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.

Now how to solve it?

  1. Project -> Properties -> Java Compiler
  2. Enable project specific settings.
  3. Then select Compiler Compliance Level to 1.6 or 1.5, build and test your app.

Crunchify-Tips-Fix-Javaa-Compiler-Major-Minor-Version

And that’s all.

J2SE 8=52,
J2SE 7=51,
J2SE 6.0=50,
J2SE 5.0=49,
JDK 1.4=48,
JDK 1.3=47,
JDK 1.2=46,
JDK 1.1=45

The version numbers mentioned above are the version of the JRE the class file is compatible with. There is another way to fix this problem – try bundling your own required JVM with your application and set JAVA_HOME from your startup.sh script.

12 thoughts on “Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0”

  1. I did already installed jdk 1.7 nd still I got error Unsupported major.minor version 51.0… anyone have idea about dis???

    Reply
    • Hey Asutosh – you could verify if the class path is correctly set on you machine by below command:

      java -version

      Try executing above under Command Prompt or Terminal app if Mac.

      Reply

Leave a Comment