方法一:修改settings.xml
eclipse中集成的maven的settings.xml文件,找了半年也没找到,我们放弃eclipse中的maven,下一个最新的maven,并在eclipse中配置该maven中的settings.xml:
eclipse在第一次编译maven项目时,会下载很多maven的插件,如果什么都没做的话,就会从默认的官网仓库地址下载。
为了加快访问速度,我们要把官网仓库地址替换为国内访问速度较快的镜像地址。
这里用的是:http://maven.aliyun.com/nexus/content/groups/public/ 这个地址,
在settings.xml中找到
然后在注释外边,mirrors标签里面配一个mirror:
<mirror>
<id>mirrorId</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
如此中央仓库(central)的默认地址就被aliyun的地址拦截了。
方法二:直接在pom.xml上改
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun</id>
<name>aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>