Search code examples
javaspringspring-bootmavenpom.xml

Class file has wrong version 61.0, should be 52.0


I want to create a Spring Boot project on Intellij Idea and i choose Java 8 and Java 1.8 sdk but when i open the pom.xml i saw my java version is 17 !? how can it possible ?

When i run my project i see this message below and how can my jars version 6.0.7 ?;

java: cannot access org.springframework.http.HttpStatus
  bad class file: /C:/Users/eegee/.m2/repository/org/springframework/spring-web/6.0.7/spring-web-6.0.7.jar!/org/springframework/http/HttpStatus.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.

Solution

  • There are three things you can check or do:

    1. Check the version of Spring Boot. For example, Spring Boot 3.X baseline requires Java 17.
    2. Specify explicitly the required Java version in the parent pom.xml (and apply it to all modules as well).
      <properties>
          <java.version>1.8</java.version>
      </properties>
      
    3. In case you use maven-compiler-plugin, you also want to check the version in its properties:
      <properties>
          <maven.compiler.target>1.8</maven.compiler.target>
          <maven.compiler.source>1.8</maven.compiler.source>
      </properties>
      
      Alternatively, specify it inside the plugin configuration itself:
      <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>1.8</source>
               <target>1.8</target>
           </configuration>
      </plugin>
      

    You can also refer to ${java.version} across the pom.xml files.