SpringBoot项目打包之java compiled by a more recent version of the Java Runtime (class file version 61.0)

文章讲述了在使用2023年Idea编译器和JDK1.8的情况下,SpringBoot项目打包时出现因maven插件版本过新导致的classfileversion错误。解决方法包括检查Idea编译器版本和POM文件中maven插件的指定版本,确保与JDK兼容。
摘要由CSDN通过智能技术生成

背景

使用2023年最新版本的idea编译器、JDK1.8,可以正常启动项目SpringBoot项目,使用maven插件打包项目时报错。

遇到的问题:

报错:

 java 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

原因:
最开始我想到的是,官方最新版本编译器强制使用JDK17,

后续验证,才发现并不是这样,你也能正常引用jdk1.8。

如果没有指定 spring-boot-maven-plugin 的版本,Maven 会使用最新版本的插件进行打包。但是,最新版本的插件可能不适用于 1.8 的 JDK

解决方法:

1、检查idea编译器中的jdk版本(编译版本)
2、检查pom文件中的maven插件版本 (推荐

可能在使用maven插件版本时,你并没有指定maven插件版本,默认引用的就是最新版本的maven插件。
这也是在升级项目时常遇到的问题,之前使用项目是可以正常打包,但后来升级了项目之后,项目可以正常打包,但到打包环节就出现了问题。

指定 spring-boot-maven-plugin 的版本

<build> 
	<plugins> 
		<plugin> 
			<groupId>org.springframework.boot</groupId> 
			<artifactId>spring-boot-maven-plugin</artifactId>         
			 <version>2.7.0</version> 
		</plugin> 
	</plugins> 
</build>

附件

具体报错:

org/springframework/boot/maven/RepackageMojo has been compiled by a more recent
 java 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

参考:

Java异常】完美解决this version of the Java Runtime only recognizes class file versions up to xx.0异常

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

someService required a bean named ‘entityManagerFactory’ that could not be found

https://www.04007.cn/article/840.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

所遇所思

你的鼓励将是我的原动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值