Maven安装及配置

警告
本文最后更新于 2023-03-09,文中内容可能已过时。

Windows 11

  • 安装

获取Maven二进制压缩包

下载Maven

image-20220604225711345
image-20220604225711345

解压到你要安装的路径

复制maven的路径

image-20220604225941739
image-20220604225941739

配置环境系统环境变量

image-20220604230130146
image-20220604230130146

image-20220604230152305
image-20220604230152305

image-20220604230223531
image-20220604230223531

新建一个变量:

  • 变量名:MAVEN_HOME
  • 变量值:你的maven路径
  • 确认

image-20220604230315579
image-20220604230315579

双击Path变量,添加maven bin目录到Path变量

image-20220604230652130
image-20220604230652130

image-20220604230746236
image-20220604230746236

确认

确认maven是否正确安装

Win+R输入cmd回车

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

image-20220604232320823
image-20220604232320823

  • 配置maven相关镜像

    maven的安装路径下,打开conf文件夹

    image-20220604231146919
    image-20220604231146919

修改settings.xml配置文件

​ 在<mirrors></mirrors>中添加如下配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>jcenter</id>
      <name>jcenter</name>
      <url>https://maven.aliyun.com/repository/central</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>google</id>
      <name>google</name>
      <url>https://maven.aliyun.com/repository/google</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>spring</id>
      <name>aliyun maven spring</name>
      <url>https://maven.aliyun.com/repository/spring</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>spring-plugin</id>
      <name>aliyun maven spring-plugin</name>
      <url>https://maven.aliyun.com/repository/spring-plugin</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>gradle-plugin</id>
      <name>aliyun maven gradle-plugin</name>
      <url>https://maven.aliyun.com/repository/gradle-plugin</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>grails-core</id>
      <name>aliyun maven grails-core</name>
      <url>https://maven.aliyun.com/repository/grails-core</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
      <id>apache snapshots</id>
      <name>aliyun maven apache snapshots</name>
      <url>https://maven.aliyun.com/repository/apache-snapshots</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  • 修改mavenlocalRepository

    <mirrors></mirrors>之上添加如下配置(具体根据自己的需求来修改):

    1
    2
    
      <!-- maven自动下载的jar包,会存放到该目录下 -->
      <localRepository>E:/Soft/Lang/Maven/repository</localRepository>

enjoy!

Buy Me a Coffee ~~
hiifong 支付宝支付宝
hiifong 微信微信
0%