在利用maven搭建 Spring MVC 项目之前,需要在本机上安装配置好 Maven

本机配置Maven

  首先去Apache官网下载所需要的maven,注意需要下载 bin.tar.gz 格式,不要下成 bin.zip 或者 src.tar.zip。

解压在自己的文件夹,我放在了 ⁩ Users⁩/⁨Yourname/⁨Applications⁩/⁨maven/apache-maven-3.6.1 下面⁩。

配置环境变量

1 vim ~/.bash_profile 

在里面添加

1 export M2_HOME=/Users/lzz/Applications/maven/apache-maven-3.6.1
2 export M2=$M2_HOME/bin
3 export PATH=$M2:$PATH

把路径改为 maven 所在的目录即可

然后使命令生效

1 source ~/.bash_profile

更改Maven默认仓库

  如果不更改仓库位置,系统会自动生成一个.m2 文件夹用以存放本地仓库,我们更改了默认仓库位置可以更方便管理

在maven下面创建仓库文件夹:Users⁩/⁨Yourname/⁨Applications⁩/⁨maven/repository

创建 setting.xml:Users⁩/⁨Yourname/⁨Applications⁩/⁨maven/setting.xml。在 apache-maven-3.6.1/bin 下面就有一个 setting.xml,我们自己配的setting.xml 就是用来替代它的。

配置setting.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4     xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 5     
 6     <pluginGroups />
 7     <proxies />
 8     <servers />
 9     
10     <localRepository>/User/lzz/Application/maven/repository</localRepository>
11     
12     <mirrors>
13         <mirror>
14             <id>alimaven</id>
15             <mirrorOf>central</mirrorOf>
16             <name>aliyun maven</name>
17             <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
18         </mirror>
19         <mirror>
20             <id>alimaven</id>
21             <name>aliyun maven</name>
22             <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
23             <mirrorOf>central</mirrorOf>
24         </mirror>
25         <mirror>
26             <id>central</id>
27             <name>Maven Repository Switchboard</name>
28             <url>http://repo1.maven.org/maven2/</url>
29             <mirrorOf>central</mirrorOf>
30         </mirror>
31         <mirror>
32             <id>repo2</id>
33             <mirrorOf>central</mirrorOf>
34             <name>Human Readable Name for this Mirror.</name>
35             <url>http://repo2.maven.org/maven2/</url>
36         </mirror>
37         <mirror>
38             <id>ibiblio</id>
39             <mirrorOf>central</mirrorOf>
40             <name>Human Readable Name for this Mirror.</name>
41             <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
42         </mirror>
43         <mirror>
44             <id>jboss-public-repository-group</id>
45             <mirrorOf>central</mirrorOf>
46             <name>JBoss Public Repository Group</name>
47             <url>http://repository.jboss.org/nexus/content/groups/public</url>
48         </mirror>
49         <mirror>
50             <id>google-maven-central</id>
51             <name>Google Maven Central</name>
52             <url>https://maven-central.storage.googleapis.com
53             </url>
54             <mirrorOf>central</mirrorOf>
55         </mirror>
56         <!-- 中央仓库在中国的镜像 -->
57         <mirror>
58             <id>maven.net.cn</id>
59             <name>oneof the central mirrors in china</name>
60             <url>http://maven.net.cn/content/groups/public/</url>
61             <mirrorOf>central</mirrorOf>
62         </mirror>
63     </mirrors>
64 </settings>
View Code

相关文章:

  • 2022-01-01
  • 2021-09-15
  • 2021-09-29
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
猜你喜欢
  • 2021-10-26
  • 2021-08-19
  • 2021-10-08
  • 2021-05-31
  • 2021-05-29
  • 2022-12-23
相关资源
相似解决方案