Maven 默认使用官方的镜像库,而该镜像库是在国外,访问的速度比较慢。本文演示如何配置国内的镜像库。
- 在用户目录中的 .m2 目录中创建一个名为: settings.xml 的文件, 并填入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?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">
<pluginGroups> </pluginGroups>
<proxies> </proxies>
<servers> </servers>
<mirrors> </mirrors>
<profiles> </profiles> </settings>
|
注意: 如文件已经存在则忽略这一步
- 在文件的 mirrors 节中填入要使用的国内镜像仓库地址,比如我们这里使用阿里的镜像地址, 则需要加入如下的内容:
1 2 3 4 5 6
| <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
|
- 在项目的 pom.xml 文件中加入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <repositories> <repository> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>
|
如果需要使用 snapshots 类型的库,需要将 snapshots.enabled 设置为true