1、maven配置镜像有两种方式,一种是在settings.xml文件中配置,一种是针对具体的项目在pom.xml文件中配置。
2、在settings.xml文件中配置镜像分为配置一个镜像源和配置多种镜像源
①配置一个镜像源
<!--直接在mirrors中配置-->
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
②配置多个镜像源
<!--在profiles节点中按照模板进行多个镜像源配置-->
<profiles>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>maven-central</id>
<repositories>
<repository>
<id>maven-central</id>
<url>http://central.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profiles>
<!--在activeprofiles中激活profiles中的配置-->
<activeProfiles>
<activeProfile>aliyun</activeProfile>
<activeProfile>maven-central</activeProfile>
</activeProfiles>
3、使用maven导入依赖,这里以使用maven中央仓库、导入pellet推理机为例
①maven导入jar包形式依赖分为组名、工件名、版本名
<dependency>
<groupId>com.github.ansell.pellet</groupId>
<artifactId>pellet-jena</artifactId>
<version>2.3.6-ansell</version>
</dependency>
②maven导入pom文件形式依赖分为组名、工件名、版本名、依赖类型
<dependency>
<groupId>com.github.ansell.pellet</groupId>
<artifactId>pellet-parent</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>
③往往只知道自己需要什么依赖,而不知道依赖是什么类型,属于什么组织。一般在浏览器搜索可以找到依赖所属官网或GitHub链接判断组织,也可以在编译器中尝试拼写依赖名,通常会有提示。获取组名和工件名后,可以在maven官网Central Repository:查找该依赖,找到依赖后可以看到依赖类型。
例如:
![](https://img-blog.csdnimg.cn/90a0eb9e20494450b7e38ee48fe8d184.png)
![](https://img-blog.csdnimg.cn/77170251c3ef4d5b8138728d8daaa90e.png)
4、在项目中配置maven镜像
<project>
...
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>mirror1</id>
<url>https://mirror1.example.com/maven2</url>
</repository>
<repository>
<id>mirror2</id>
<url>https://mirror2.example.com/maven2</url>
</repository>
</repositories>
...
</project>