Blog |

How to Fix java.lang Illegal Argument Exception Unsupported Class File Major Version 61

How to Fix java.lang Illegal Argument Exception Unsupported Class File Major Version 61
Table of Contents

The "Unsupported class file major version 61" error in Java means you're trying to run a Java program that's too advanced for the version of Java you have installed. To fix this, either update your Java to version 17 or newer, otherwise recompile the program with an older Java version that matches your runtime environment.

This error often occurs when using libraries, frameworks, or tools that internally check class file versions and throw an IllegalArgumentException if they encounter a version they don't support.

What’s “major version 61” mean?

Each compiled Java class file contains metadata, including a "major version number," which indicates the version of the Java Development Kit (JDK) used to compile that class file. This version number helps the Java Virtual Machine (JVM) to identify whether it can support running the class file based on the JVM's own version.

"Major version 61" refers to the internal version number used by Java to represent Java SE 17. Since you see this version number in your error, it means your current Java runtime environment is older than Java 17 and you need to update to Java 17 or higher to run the class file without issues.

How to fix the error by updating your version of Java

Updating Java to a newer version will solve compatibility issues and allow you to run applications compiled with newer JDK versions. Click the button below to go to Oracle’s website and install the latest version so you can run your program without this error.

Get Java SE SDK

Recompile your code with an older version of Java

If upgrading your Java runtime is not an option, you can recompile your code with an older version of the JDK that matches the version of your runtime environment. This route might require you to adjust your code to be compatible with the older Java version if you're using features introduced in newer versions of Java.

Since the specifics of this depends on what version you want to use, here’s a general process to follow:

1. Install the older JDK

First, you need to install the JDK version you want to compile your code against. You can download older JDKs from the Oracle website at https://www.oracle.com/java/technologies/downloads/archive/

2. Configure your development environment

After installing the older JDK, configure your development environment to use it. You’ll need to set the JAVA_HOME environment variable and update the PATH variable to point to the older JDK's bin directory.

3. Adjust project settings (if using an IDE)

If you are using an IDE like IntelliJ IDEA, Eclipse, or NetBeans, you need to adjust the project's SDK setting to the older JDK version:

  • IntelliJ IDEA: Go to File > Project Structure > Project and select the older JDK from the Project SDK dropdown.
  • Eclipse: Right-click on your project, go to Properties > Java Build Path > Libraries, and set the JRE System Library to the older JDK. Also, adjust the compiler compliance level in Properties > Java Compiler.
  • NetBeans: Right-click your project, select Properties > Sources to change the Source/Binary Format, and Properties > Libraries to set the Java Platform.

4. Set Source and Target Compatibility

When compiling from the command line or through build tools (like Maven or Gradle), you need to specify the source and target compatibility versions. This tells the compiler to ensure your code is compatible with older Java versions.

Command Line

Use the javac tool with -source and -target options. For example:

javac -source 1.8 -target 1.8 MyProgram.java
This compiles MyProgram.java for Java 8.

Maven

In your pom.xml, set the maven-compiler-plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Adjust the <source> and <target> to the desired Java version, like 1.8 for Java 8.

Gradle

In your build.gradle, specify the source and target compatibility:

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

Again, adjust the version to your needs.

5. Recompile your code for the older Java version

Now, recompile your code so that it’s compatible with the older Java version if you're using features introduced in newer versions of Java.

6. Test your program

After recompilation, thoroughly test your application to ensure that changing the Java version hasn't introduced any bugs.

So there you have it. The error “java lang illegalargumentexception unsupported class file major version 61” is essentially Java's way of saying, "I cannot run this class because it was built with a version of Java that's newer than me." To resolve it, you need to either upgrade your Java runtime to match the version required by the class files (at least Java 17 in this case) or recompile the source code with a target version that matches your runtime environment's Java version.

Track, Analyze and Manage Errors With Rollbar

Managing 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 Resources

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

Error Monitoring

Start continuously improving your code today.

Get Started Shape