# （三）Maven 设置仓库地址





#### 修改本地仓库地址
---
maven 用来管理我们的 Java 第三方库，我们需要设置仓库的本地地址来存放这此第三方库。

打开 Maven 目录下的配置文件（__\apache-maven-3.5.0\conf\settings.xml__) ， 找到 `<localRepository> ..</localRepository>` 标签。

```
<!-- localRepository
 | The path to the local repository maven will use to store artifacts.
 |
 | Default: ${user.home}/.m2/repository
-->
<localRepository>D:/Java/maven/repo</localRepository>

```
Maven 默认将本地仓库设置在 __${user.home}/.m2/repository__ 目录下，这里修改为 __D:/Java/maven/repo__ 路径。

#### 设置中央仓库地址
---
中央仓库即当我们要用到 Java 的第三方库时应该去哪里下载。

同样打开 Maven 目录下的配置文件（__\apache-maven-3.5.0\conf\settings.xml__) ， 找到 `<mirrors>..</mirrors>` 标签。

```
<mirrors>
  <!-- mirror
   | Specifies a repository mirror site to use instead of a given repository. The repository that
   | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
   | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
   |
  <mirror>
    <id>mirrorId</id>
    <mirrorOf>repositoryId</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://my.repository.com/repo/path</url>
  </mirror>
   -->
  <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <!--<mirrorOf>central</mirrorOf> -->
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>
```
这里将 Maven 的中央仓库地址修改为 aliyun ，国内访问速度会更快。




原始封面

![课程图片](https://images.unsplash.com/photo-1501959181532-7d2a3c064642?w=300)


