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?
- Project -> Properties -> Java Compiler
- Enable project specific settings.
- Then select Compiler Compliance Level to 1.6 or 1.5, build and test your app.
And that’s all.
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.Would love to know what you think. Chime in and share it as a comment. Don’t forget to share this guide!