java: cannot access org.springframework.boot.SpringApplication bad class file
Asked Answered
F

8

19
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.
Fuqua answered 11/9, 2022 at 13:31 Comment(0)
P
20

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.

Polarimeter answered 11/9, 2022 at 14:22 Comment(1)
Can we substitute this with an OpenJDK version? – Cordiform
T
18

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 -->
Trinl answered 1/12, 2022 at 18:58 Comment(0)
F
8

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.

enter image description here

Fuqua answered 11/9, 2022 at 13:53 Comment(2)
Don't use snapshot versions, because snapshot versions are currently being developed by the spring boot Team & you don't want to use them when creating a project. Use the released versions. – Pythagorean
Here if you want to use spring boot 3 then select Java version 17 – Pythagorean
P
8

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! πŸ‘¨β€πŸ’»

Pythagorean answered 26/12, 2022 at 20:44 Comment(1)
Perfectly working – Pythagorean
C
4

from 3.0.0 to 2.7.3 , I changed. then it went all fine.

Complicate answered 28/11, 2022 at 5:30 Comment(0)
B
0

Here are few solutions which may help you

  1. 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>
  1. 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
Bronchopneumonia answered 28/11, 2022 at 17:7 Comment(0)
C
0

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.

Cleavable answered 26/12, 2022 at 19:16 Comment(0)
R
0

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>
Rebarebah answered 15/9, 2023 at 14:14 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.