Sentry Answers>Java>

How to Fix Unsupported major.minor Version Error in Java

How to Fix Unsupported major.minor Version Error in Java

Venter C.

The Problem

You get the following error when trying to run your Java program:

Click to Copy
java.lang.UnsupportedClassVersionError: Unsupported major.minor version

The Solution

A major.minor version error occurs when the Java Runtime Environment (JRE) version used to run a program is older than the Java Development Kit (JDK) version used to compile its code. You can resolve this by:

  • Checking and updating your JDK and JRE versions
  • Compiling the code with an older version of JDK
  • Ensuring you’re using the correct JAVA_HOME and PATH
  • Configuring your IDE for a specific Java version

Check the Java Version Used to Compile Code

If you have access to the compiled .class or .jar files, use the following command to check the version they were compiled with:

Click to Copy
javap -verbose MyClass | grep "major"

You will see an output like:

Click to Copy
major version: 61

Use the Correct JDK and JRE Versions

Ensure the JRE running your application is at least as recent as the JDK used to compile the code. For example, if the class is compiled with Java 17 (major version 61), you need to run it with Java 17 or higher.

Click to Copy
java -version javac -version

If the java version is older than javac, install the appropriate JDK or JRE version, or update your Java version.

Compile with a Lower Java Version (Optional)

If you need to run the code on a system with an older JRE, you can recompile your Java code with compatibility flags to generate bytecode compatible with older versions.

The following command compiles the code to be compatible with Java 8 (major version 52):

Click to Copy
javac --release 8 MyClass.java

Set the Correct JAVA_HOME and PATH

Ensure that your environment is configured to use the correct version of Java by setting JAVA_HOME and PATH.

On Linux/macOS:

Click to Copy
export JAVA_HOME=/path/to/your/java export PATH=$JAVA_HOME/bin:$PATH

On Windows (CMD):

Click to Copy
set JAVA_HOME=C:\path\to\your\java set PATH=%JAVA_HOME%\bin;%PATH%

Install the Correct Java Version

If the code requires a specific version, download and install it from the official Java website or an open-source distribution like AdoptOpenJDK.

Update the Java Version in Your IDE

If you are using an IDE like IntelliJ IDEA or Eclipse, make sure the project settings are configured to use the correct JDK version.

Note

Each version of Java assigns a unique major.minor version number to compiled class files, so running any class with a newer major version on an older Java virtual machine will return major.minor version error.

Further Reading

  • Sentry BlogException Handling in Java (with Real Examples)
  • Syntax.fmListen to the Syntax Podcast
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2025 • Sentry is a registered Trademark of Functional Software, Inc.