一、在项目文件下的 pom.xml文件下添加一下代码(jdk11为例)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.webrx</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<!-- 配置当前项目的jdk版本信息 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
二、设置通过Maven创建的工程的JDK版本 在下载的Maven目录中找到settings.xml文件在profiles标签加入如下配置
<!-- maven/conf/settins.xml 文件添加如下配置,建立的java项目默认使用java13 -->
<profiles>
<profile>
<id>jdk-11</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>11</jdk>
</activation>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>