“Class file has wrong version 61.0, should be 52.0.”

huangapple go评论91阅读模式
英文:

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 ?

当我打开 pom.xml 时,我选择了 Java 8 和 Java 1.8 SDK 创建 Spring Boot 项目,但我看到我的 Java 版本是 17!?这怎么可能?

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

当我运行我的项目时,我看到下面的消息,我的 jar 版本是 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.

英文:

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.

答案1

得分: 4

  1. 检查Spring Boot的版本。例如,Spring Boot 3.X基线需要Java 17。
  2. 在父pom.xml中明确指定所需的Java版本(并将其应用于所有模块):
    <properties>
        <java.version>1.8</java.version>
    </properties>
    
  3. 如果使用maven-compiler-plugin,还需要检查其属性中的版本:
    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>
    

    或者,可以在插件配置中明确指定:

    <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
             <source>1.8</source>
             <target>1.8</target>
         </configuration>
    </plugin>
    
英文:

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).
    &lt;properties&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;/properties&gt;
    
  3. In case you use maven-compiler-plugin, you also want to check the version in its properties:
    &lt;properties&gt;
        &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
        &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
    &lt;/properties&gt;
    

    Alternatively, specify it inside the plugin configuration itself:

    &lt;plugin&gt;
         &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
         &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
         &lt;configuration&gt;
             &lt;source&gt;1.8&lt;/source&gt;
             &lt;target&gt;1.8&lt;/target&gt;
         &lt;/configuration&gt;
    &lt;/plugin&gt;
    

答案2

得分: 0

如果您正在使用JDK >17和最新的库,例如Spring 6,请使用版本5.1.0(发布说明)。如果您使用较旧的JDK或库,请使用版本4.44.0(文档)。
查看它

对我来说,您应该使用4.44.0
当我解决了问题后,它对我起作用了

英文:

If you are using JDK >17 and up-to-date libraries like Spring 6, use version 5.1.0 (Release Notes). If you are on older JDK or library, use version 4.44.0 (documentation).
Look on it

It seems to me that ypu should use 4.44.0
It worked for me when I corrected with problem

huangapple
  • 本文由 发表于 2023年4月17日 10:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定