[Solved] Java class file has wrong version 61.0

Learn to solve the Java compiler exception “Java class file has wrong version” while migrating an application to Spring 6 or Spring boot 3.

Intellij SDK Version Configuration

Learn to solve the Java compiler exception while migrating your Java application. For example, migrating a Spring application to Spring 6 or Spring Boot 3.

1. Problem

We may face the error “Java class file has wrong version 61.0” when a dependent third-party library is expected the minimum supported Java version 17.

For example, the baseline version for Spring framework 6 and Spring boot 3 is Java 17. If we compile a Spring boot 3 application with a lower version of JDK then we will get the following compilation error:

java: cannot access org.springframework.boot.SpringApplication
  bad class file: /C:/devsetup/m2/org/springframework/boot/spring-boot/3.0.0/
  spring-boot-3.0.0.jar!/org/springframework/boot/SpringApplication.class

    class file has wrong version 61.0, should be 52.0

    Please remove or make sure it appears in the correct subdirectory of the classpath.

Similarly, we get the error “class file has wrong version 61.0, should be 55.0” when the same application is compiled with Java 11.

2. Solution

To fix the compilation issue, we must compile the application with a minimum Java version of 17. Once we upgrade the application to Java 17, the error will be fixed.

In a Maven application, the Java version should be updated like the following configuration in pom.xml.

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>3.0.0</version>
</parent>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>17</maven.compiler.source>
  <maven.compiler.target>17</maven.compiler.target>
</properties>

Also, do not forget to change the project settings if you are using an IDE. For example, in IntelliJ Idea, you must change the SDK version in project settings.

After making the above changes, the compiler error will be gone.

3. Java Class File Versions

The following are the class file versions from Java 8.

Java VersionClass File Version
Java 852.0
Java 953.0
Java 1054.0
Java 1155.0
Java 1256.0
Java 1357.0
Java 1458.0
Java 1559.0
Java 1660.0
Java 1761.0
Java 1862.0
Java 1963.0
Java 2064.0
Java 2165.0
Java 2266.0
Java 2367.0
Java 2468.0

The version number in the Java exception will help you understand what JDK version is being used, and what is expected.

Happy Learning !!

Weekly Newsletter

Stay Up-to-Date with Our Weekly Updates. Right into Your Inbox.

Comments

Subscribe
Notify of
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.