【已解决】this version of the Java Runtime only recognizes class file versions up to 52.0

1 报错问题

在把springboot项目打包了jar之后,准备本地运行一下

java -jar xxx-0.0.1-SNAPSHOT.jar

然后报错:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/myweb/xxxApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

2 可能的原因

  1. 编译版本和运行版本不一致,可能是编译版本高于运行版本导致的

修改pom.xml, 将此版本改为java -version版本

    <properties>
        <java.version>11</java.version>
    </properties>
  1. spring-boot-maven-plugin增加<parent>的版本号

如果没指定spring-boot-maven-plugin 的版本,就会拿取最新的版本打包,但是目前高版本的为未必适合1.8的jdk,如果它确实是您想要用于 spring boot 项目的版本。

为了解决这个问题,就必须明确指定spring-boot-maven-plugin的版本。

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.7.9</version> //增加<parent>的版本号
    </plugin>

3 重新打包,运行

两种方式都尝试了一下,可以运行了!

如果运行遇到端口被占用的问题

  1. 输入netstat -lnp命令查看端口信息

  1. 使用sudo kill xxx进行删除


参考链接:

this version of the Java Runtime only recognizes class file versions up to 55.0 at ...

Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file

### 解决Eclipse Java Runtime Class File Version 不兼容问题 当遇到 `Java Runtime class file version 52.0` 的不兼容提示时,这通常意味着编译器使用的JDK版本与运行环境中的JRE/JDK版本存在差异。Class文件的主要版本号对应特定的Java版本: - 版本号 **52** 对应的是 **Java 8** 为了确保项目的正常运作,建议采取以下措施来调整开发环境中涉及的各种配置。 #### 修改 Eclipse 编译器设置 在Eclipse IDE中,可以通过更改项目属性内的Java Compiler选项来指定目标合规级别以及所要使用的JRE: ```plaintext Project -> Properties -> Java Compiler ``` 确认已勾选 "Enable project specific settings" 并将 Compliance level 设置为合适的值 (例如1.8),同时也要保证 JDK compliance 和 Generated .class files compatibility 都指向相同的大版本[^1]。 #### 调整构建路径上的 JRE 系统库 同样,在同一窗口下的 Libraries标签页里找到当前关联的JRE System Library条目并移除它;接着点击 Add Library...按钮重新添加正确的JRE版本作为新的依赖项。 #### 更新 Gradle 或 Maven 构建工具配置 如果项目采用Gradle或Maven管理,则还需要同步更新这些工具的相关设定以保持一致性。对于Gradle而言,可以在build.gradle文件内加入如下声明: ```groovy sourceCompatibility = '1.8' targetCompatibility = '1.8' ``` 而对于Maven pom.xml则需相应地编辑 `<properties>` 下面的内容: ```xml <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> ``` 通过上述操作可以有效解决由不同版本间产生的二进制格式冲突引发的一系列异常情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值