1.Maven前置依赖
检查电脑是是否安装java
2.下载maven
解压 maven 压缩包,
并创建相应的maven本地仓库的路径。
打开 conf文件夹中 修改 settings.xml 文件
2.
3. settings.xml 的修改和研究
setting.xml的配置文件分类(更改配置的本地仓库)
(1)直接修改Maven中conf文件夹中的setting.xml文件
注:此时更改后,所有的用户都会受到影响,而且如果maven进行升级,那么所有的配置都会被清除,所以要提前复制和备份/conf/settings.xml文件
(2)在.m2文件夹下建立一个setting·xml文件
3.(多说一下)项目里的pom.xml
有个优先级的,应该是pom>用户级别>全局级别
例:如果pom中不配置,就取用户级别,如果用户级别也没有配置,就取全局级别
故:一般情况下不推荐配置全局的settings.xml
第一点:镜像的配置
setting.xml里面有个mirrors节点,用来配置镜像URL。mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性。
mirror也不是按settings.xml中写的那样的顺序来查询的。所谓的第一个并不一定是最上面的那个。
当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。
在setting·xml中添加如下代码:
<mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> <mirror> <!--This is used to direct the public snapshots repo in the profile below over to a different nexus group --> <id>nexus-public-snapshots</id> <mirrorOf>public-snapshots</mirrorOf> <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url> </mirror> </mirrors>
第二点:指定本地路径和修改
这是直接修改的maven中conf中的setting.xml文件,此时配置的maven的本地仓库是属于用户范围的。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>E:/Program/apache-maven-3.3.9/repository</localRepository> --> <localRepository>D:/repository</localRepository>
原文:https://www.cnblogs.com/wqbin/p/11288259.html