修改已经建好的maven的JDK的版本,在父模块中修改JDK的信息
在这里先看一下本地的配置,我这里先设置的17版本
![](https://img-blog.csdnimg.cn/img_convert/a1bbf5e9e3b98148a95bdf9e12f5eb5c.png)
出现这种情况的解决办法
![](https://img-blog.csdnimg.cn/img_convert/4aaac851ec5e54799e7ae7b2548f6b73.png)
先修改根目录的setting.xml文件,将里边的JDK版本全部换为1.8,然后保存即可。将17全部换为1.8 setting.xml的路径为:D:\maven\conf(这是我安装的路径),如果不知道的话,
![](https://img-blog.csdnimg.cn/img_convert/6f2bd8b199a442a3ba22639babbf16d9.png)
这里的JDK文件,哪个版本的JDK用的多设置为哪个
![](https://img-blog.csdnimg.cn/img_convert/fa4d557b498861ac1fe3f5b2e4a3501f.png)
修改设置里的的JDK,源和依赖全部需改1.8的版本。
![](https://img-blog.csdnimg.cn/img_convert/2d8102ccea56769caaa3b2600730fb56.png)
在项目设置里边也要修改为1.8版本。
![](https://img-blog.csdnimg.cn/img_convert/3e36096da64261004f7148a3165709a1.png)
在设置里边找到maven目录,将正在导入修改为1.8版本
![](https://img-blog.csdnimg.cn/img_convert/6953fcefe3a5b82bf1bab1631a749443.png)
运行程序的这里也要修改为1.8版本。
![](https://img-blog.csdnimg.cn/img_convert/f1974ba809241a4815fee52e75491213.png)
这里一定要进行从新写入,不然还是无法运行成功
![](https://img-blog.csdnimg.cn/img_convert/40c032827b6abb74fff980d7fe9506e4.png)
如果还是不行的话,进行数据的清除,按顺序进行操作即可
![](https://img-blog.csdnimg.cn/img_convert/bd944e6592104a4fb396d0c019b698ac.png)
3.在修改本地文件设置的jdk
![](https://img-blog.csdnimg.cn/img_convert/1b8cb042d2c9846c698821c119fa34cc.png)
最终运行的结果
![](https://img-blog.csdnimg.cn/img_convert/968dd3927ea44f792becad0b66371203.png)
控制maven项目jdk版本
conf/settings.xml 文件配置
<!-- 配置项目开发编译的jdk版本 -->
<profiles>
<profile>
<id>jdk-17</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>17</jdk>
</activation>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
2)maven项目pom.xml文件配置
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>