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 Version | Class File Version |
---|---|
Java 8 | 52.0 |
Java 9 | 53.0 |
Java 10 | 54.0 |
Java 11 | 55.0 |
Java 12 | 56.0 |
Java 13 | 57.0 |
Java 14 | 58.0 |
Java 15 | 59.0 |
Java 16 | 60.0 |
Java 17 | 61.0 |
Java 18 | 62.0 |
Java 19 | 63.0 |
Java 20 | 64.0 |
Java 21 | 65.0 |
Java 22 | 66.0 |
Java 23 | 67.0 |
Java 24 | 68.0 |
The version number in the Java exception will help you understand what JDK version is being used, and what is expected.
Happy Learning !!
Comments