[Solved] Java class file has wrong version 61.0
The message “Java class file has wrong version 61.0” could appear when we try to use a third-party library that requires Java version 17, which is the minimum supported version.
For instance, Java 17 is the baseline version for Spring Boot 3 and Spring Framework 6. Compiling a Spring Boot 3 application with a JDK version that is less than the recommended one will result in the compilation error that follows:
Error when application is complied with Java 8 :
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.
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>