Blog |

How to Fix Unsupported major.minor Version 52.0 Error in Java

How to Fix Unsupported major.minor Version 52.0 Error in Java
Table of Contents
Try Rollbar Today

Proactively discover and resolve errors

The unsupported major.minor version error is thrown in Java when a class is compiled using a higher version of the Java Development Kit (JDK) but executed on a lower version of the Java Runtime Environment (JRE). The exact cause is printed on the version e.g. in the case of major.minor version 52.0, the class is compiled using JDK 8 since major version 52 corresponds to Java SE 8.

This error can usually be fixed by running the application on the same (or higher) JRE version as the JDK.

 

What Causes Unsupported major.minor Version Error

The unsupported major.minor version error occurs due to a Java version mismatch. When a Java project is compiled on a higher version of Java (e.g. JDK 1.8) but executed on a lower version (e.g. JRE 1.7), this error is thrown.

Java is backwards compatible, which means a Java class file or binary (JAR file) compiled on a lower version of Java can be executed on a higher version. However, the opposite of this is untrue, i.e. a class compiled on a higher version of Java cannot be executed on a lower version. This is because the higher version usually contains features that are not supported by the lower version on which the application executes. When this happens, the unsupported major.minor version error occurs.

 

Unsupported major.minor Version Error Example

Here is an example of an unsupported major.minor version error thrown when a Java class is compiled using Java 1.8, but executed using Java 1.7:

public class UnsupportedVersionErrorExample {
    public static void main(String args[]) {
        System.out.println("Hello World");
    }
}

Running the above code produces the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: UnsupportedVersionErrorExample : 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)

In the above example, Java 1.8 is used to compile the code, which is higher than the Java version it is executed on (1.7). Since the major version 52 corresponds to Java SE 8, the unsupported major.minor version 52.0 error is thrown.

 

How to Fix Unsupported major.minor Version 52.0 Error

To fix the unsupported major.minor version 52.0 error, the version of Java used to build the Java application should be the same (or lower) as the version installed on the production server where the application will run. To achieve this, the following can be considered:

  • The JRE version on the production environment should be upgraded to the latest release or the same as the one on the build environment.
  • If the above is not possible, the JDK version on the build environment should be downgraded to be the same (or lower) as the version on production.
  • The Java compiler's cross compilation option can also be used to generate the .class file for production using the javac -target command. For example, if the build environment is using Java 1.8 and production is using Java 1.7, the following command can be used to generate .class files for Java 1.7:
javac -target 1.7 <path-to-java-class>

 

Track, Analyze and Manage Errors With Rollbar

Rollbar in action

Managing Java errors and exceptions in your code is challenging. It can make deploying production code an unnerving experience. Being able to track, analyze, and manage errors in real-time can help you to proceed with more confidence. Rollbar automates error monitoring and triaging, making fixing Java errors easier than ever. Sign Up Today!

Related Posts

See all posts

"Rollbar allows us to go from alerting to impact analysis and resolution in a matter of minutes. Without it we would be flying blind."

Start continuously improving your code today.

Get Started Shape