# Maven安装及配置


# Windows 11

- ### **安装**

**获取Maven二进制压缩包**

[下载Maven](https://maven.apache.org/download.cgi)

![image-20220604225711345](https://img.nil.lc/img/202206042257847.png &#34;img&#34;)



**解压到你要安装的路径**



**复制**`maven`**的路径**

![image-20220604225941739](https://img.nil.lc/img/202206042259818.png &#34;img&#34;)

**配置环境系统环境变量**

![image-20220604230130146](https://img.nil.lc/img/202206042301248.png &#34;img&#34;)

![image-20220604230152305](https://img.nil.lc/img/202206042301363.png &#34;img&#34;)

![image-20220604230223531](https://img.nil.lc/img/202206042302585.png &#34;img&#34;)

**新建一个变量：**

 - 变量名：`MAVEN_HOME`
 - 变量值：你的maven路径
 - 确认

![image-20220604230315579](https://img.nil.lc/img/202206042303688.png &#34;img&#34;)

**双击`Path`变量，添加maven bin目录到Path变量**

![image-20220604230652130](https://img.nil.lc/img/202206042306199.png &#34;img&#34;)

![image-20220604230746236](https://img.nil.lc/img/202206042307284.png &#34;img&#34;)

**确认**

**确认`maven`是否正确安装**

`Win&#43;R`输入`cmd`回车

```shell
mvn -v # or mvn --version 看到输出如下信息表明maven已正确安装
```

![image-20220604232320823](https://img.nil.lc/img/202206042323888.png &#34;img&#34;)



- ### 配置maven相关镜像

  **在`maven`的安装路径下，打开`conf`文件夹**

  ![image-20220604231146919](https://img.nil.lc/img/202206042311002.png &#34;img&#34;)

​	**修改`settings.xml`配置文件**

​		在`&lt;mirrors&gt;&lt;/mirrors&gt;`中添加如下配置：

```xml
	&lt;mirror&gt;
      &lt;id&gt;alimaven&lt;/id&gt;
      &lt;name&gt;aliyun maven&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/public&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;jcenter&lt;/id&gt;
      &lt;name&gt;jcenter&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/central&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;google&lt;/id&gt;
      &lt;name&gt;google&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/google&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;spring&lt;/id&gt;
      &lt;name&gt;aliyun maven spring&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/spring&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;spring-plugin&lt;/id&gt;
      &lt;name&gt;aliyun maven spring-plugin&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/spring-plugin&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;gradle-plugin&lt;/id&gt;
      &lt;name&gt;aliyun maven gradle-plugin&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/gradle-plugin&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;grails-core&lt;/id&gt;
      &lt;name&gt;aliyun maven grails-core&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/grails-core&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;

    &lt;mirror&gt;
      &lt;id&gt;apache snapshots&lt;/id&gt;
      &lt;name&gt;aliyun maven apache snapshots&lt;/name&gt;
      &lt;url&gt;https://maven.aliyun.com/repository/apache-snapshots&lt;/url&gt;
      &lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
    &lt;/mirror&gt;
```



- ### 修改`maven`localRepository

  在`&lt;mirrors&gt;&lt;/mirrors&gt;`之上添加如下配置（具体根据自己的需求来修改）：

  ```xml
    &lt;!-- maven自动下载的jar包，会存放到该目录下 --&gt;
    &lt;localRepository&gt;E:/Soft/Lang/Maven/repository&lt;/localRepository&gt;
  ```

  

# enjoy！


---

> 作者: hiifong  
> URL: https://f.style/maven/  

