java: cannot access org.springframework.boot.SpringApplication
bad class file: /C:/Users/xyz/.m2/repository/org/springframework/boot/spring-boot/3.0.0-SNAPSHOT/spring-boot-3.0.0-20220910.145857-773.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.
The reason is Spring Boot 3 requires java 17, as stated in Preparing for Spring Boot 3.0.
class file has wrong version 61.0, should be 52.0
Referring to List of Java class file format major version numbers?. and similar question Class file has wrong version 52.0, should be 50.0 It indicates that you are using java 8 but the class file is compiled for java 17.
Change your springboot version to the previous stable version.
Before :
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
After:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
If you have java 8 installed on your machine and if you go to the spring initializer website and create an application by selecting Spring boot 3.0.0 (SNAPSHOT) and packaging as Jar and version as 8, then generated zip file will have version as 11 on pom even though you selected version as 8. which means, your local machine is having java version 8, and the generated zip file is having version 11 on the pom.
I changed the version from 2.7.5 to 3.0.1 and it faced this issue.
java: cannot access org.springframework.boot.SpringApplication bad class file
To resolve this issue, the spring boot 3 needs at least Java 17 or a higher version of Java.
I also faced this issue because I was using Java 11 so when i convert to Java 17 in pom.xml
<properties>
<java.version>17</java.version>
</properties>
and project structure of project and modules as well then the project worked perfectly
Note: SNAPSHOT, M1, M2, M3, and M4 releases typically WORK IN PROGRESS. The Spring team is still working on them, Recommend NOT using them.
I hope this helps! Let me know if you have any questions or if there's anything else I can assist you with.
Happy coding! π¨βπ»
from 3.0.0 to 2.7.3 , I changed. then it went all fine.
Here are few solutions which may help you
- Change Thymeleaf version from 3.0.0 to 3.1.0
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>3.1.0</version>
</dependency>
- Try changing your sdk in project structure
- Press Ctrl + Alt + Shift + S
- Select Project under Project Settings
- Change your SDK to openjdk-17 Oracle OpenJDK Version 17.0.4 or openjdk-18 Oracle OpenJDK Version 18.0.2
- If you don't have it, download it from Oracle site and press Add SDK button under SDK:
- Any SDK version above 17 will work
- Press Apply and press OK
- Right click anywhere on your pom.xml file and select Maven
- Then select Reload project
- Wait for the project to be reloaded
- Now Build your project and Run it
Try changing your Spring Boot version from the pom.xml file.
I changed the version from 3.0.0 to 2.0.2.RELEASE and it worked fine.
The problem occurs because Spring Boot version 3 requires Java version 17 to run whereas you are trying to run with Java version 8.
I got this error
java: cannot access org.springframework.boot.SpringApplication bad class file: /C:/Users/homa/.m2/repository/org/springframework/boot/spring-boot/3.1.3/spring-boot-3.1.3.jar!/org/springframework/boot/SpringApplication.class class file has wrong version 61.0, should be 55.0 Please remove or make sure it appears in the correct subdirectory of the classpath.
when I changed version 11 to 17 my test was passed.
<properties>
<java.version>17</java.version>
</properties>
© 2022 - 2024 β McMap. All rights reserved.