How to fix Unsupported major.minor version 52.0 in Java

java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 52.0 and similar exceptions occur when the JDK version, more specifically javac version, the code is compiled with is newer then JVM used for running it.

There is a meta information inside Java class files, including minor and major Versions of Class File Format, which tells that the code could be run on indicated JVM versions.
List of Java class file format major versions
JDK 1.1 = 45 (0x2D hex)
JDK 1.2 = 46 (0x2E hex)
JDK 1.3 = 47 (0x2F hex)
JDK 1.4 = 48 (0x30 hex)
JDK 5 = 49 (0x31 hex)
JDK 6 = 50 (0x32 hex)
JDK 7 = 51 (0x33 hex)
JDK 8 = 52 (0x34 hex)

You can specify on which version of JVM your code will be running, but in this case your current JDK version can’t be older then specified:
~ $ javac -source 1.6 MyClass.java

Options how to fix such exception:

  • Upgrade JVM version to the version the code is compiled with
  • Find jar compiled with a JDK compatible with your JVM
  • Get sources and recompile them with your JDK

How it can be reproduced

~ $ javac -version
javac 1.8.0_40
~ $ javac Test.java
~ $ java7 Test
Exception in thread "main" java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Leave a Reply