[Solved] Java class file has wrong version 61.0

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.

Happy Learning !!

Leave a Reply

2 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.

Our Blogs

REST API Tutorial