1.配置Maven国内镜像
打开 c:/maven/conf/settings.xml 文件,直接将原始默认内容改为:
<?xml version="1.0" encoding="UTF-8"?><settings xmlns = "http://maven.apache.org/SETTINGS/1.2.0"xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation = "http://maven.apache.org/SETTINGS/1.2.0https://maven.apache.org/xsd/settings-1.2.0.xsd" ><!-- localRepository Default: ${user.home}/.m2/repository --><localRepository> c:/maven/repo </localRepository><pluginGroups></pluginGroups><proxies></proxies><servers></servers><mirrors><!-- https://developer.aliyun.com/mirror/ 阿里镜像仓库 --><mirror><id> aliyunmaven </id><mirrorOf> * </mirrorOf><name> 阿里云公共仓库 </name><url> https://maven.aliyun.com/repository/public </url></mirror></mirrors><profiles><!-- maven 项目全局默认配置 jdk 版本信息 17 --><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><!-- maven 项目全局默认配置 jdk 版本信息 1.8 --><!--<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>--></profiles></settings>
这里便写了两种jdk信息,使用哪种可以把另一种直接注释掉
2.idea配置
3.建立Maven项目
4.pom.xml
Maven项目根目录下有pom.xml文件
<?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.example</groupId>
<artifactId>m1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>