由于maven默认设置的是指向国外的中央仓库,所以下载的时候会很慢,甚至有时候卡住不动。所以如果想让maven快速的下载相关的jar包,可以将地址设置成阿里云的中央仓库镜像,下边介绍如何更改maven的中央仓库地址设置成阿里云的中央仓库镜像
- 打开本地maven的conf文件夹,打开settiongs.xml
- 找到mirrors的标签,在里边添加这一段
<!-- 阿里云中央仓库 -->
<mirror>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
3. 创建一个pom.xml文件,然后再当前文件目录进入dom界面,输入mvn clean install
,出现下边的链接表示设置成功
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xn.maven</groupId>
<artifactId>tmaven</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>tmaven</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- 下载Spring-4.2.17 -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.17.RELEASE</version>
</dependency>
</dependencies>
</project>
或者使用第二个方法,还是在maven的setting.xml中找到repositories标签,并在里面添加下面的内容,记得保存
<repository>
<id>aliyunmaven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
测试方法在上边,然后就体验奔放的速度了