maven项目jdk版本配置及常见错误Error:java: 无效的目标发行版: 8解决

IDEA配置

maven JDK版本配置

apache-maven-x.x.x\conf\settings.xml文件添加如下配置

setting.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

	<localRepository>E:\maven\repository</localRepository>

	<mirrors>
		<mirror>
      <id>aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
	</mirrors>

	<profiles>
		<profile>
			<id>jdk18</id>
			<activation>
				<activeByDefault>true</activeByDefault>
				<jdk>1.8</jdk>
			</activation>
			<properties>
				<maven.compiler.source>1.8</maven.compiler.source>
				<maven.compiler.target>1.8</maven.compiler.target>
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
			</properties>
		</profile>
		<profile>
			<id>jdk17</id>
			<properties>
				<maven.compiler.source>1.7</maven.compiler.source>
				<maven.compiler.target>1.7</maven.compiler.target>
				<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
			</properties>
		</profile>
	</profiles>
</settings>

maven配置

maven配置
在这里插入图片描述在这里插入图片描述

项目pom.xml中jdk版本配置(不配置使用maven中setting.xml的默认jdk版本)

pmo.xml

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArguments>
						<extdirs>lib</extdirs>
					</compilerArguments>
				</configuration>
			</plugin>
		</plugins>
	</build>

全局配置JDK版本setting配置jdk版本

project配置JDK版本

project配置jdk版本

modules配置jdk版本

modules配置jdk版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误信息指出了目标发行版无效,是因为项目使用的JDK版本Maven构建时使用的JDK版本不一致所致。解决这个问题的一个方法是确保项目中使用的JDK版本Maven配置中的JDK版本一致。你可以按照以下步骤操作: 1. 删除原有的JDK配置(如果存在)并添加目标JDK版本配置信息。 2. 在项目的pom.xml文件中,添加一个profile标签,并在其中配置目标JDK版本。例如,如果你需要使用1.8版本的JDK,可以按照下面的配置信息添加到profile标签中: ```xml <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> ``` 3. 保存并关闭pom.xml文件,并重新构建项目。 这样,你的项目就会使用和Maven配置中一致的JDK版本进行构建,从而解决了"Error:java: 无效目标发行版: 17"的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [IDEA导入外部项目Error:java: 无效目标发行版: 11的解决方法](https://download.csdn.net/download/weixin_38704485/12820791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [JAVA无效目标发行版 17’的解决方案](https://blog.csdn.net/a1056139525/article/details/124781292)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值