您的位置:首页 > 其它

Maven 更换远程仓库地址

2017-08-03 17:54 477 查看
1.第一种方式,通过setting.xml的方式配置数据源

该文件路径D:\IDE\apache-maven-3.2.3\conf\setting.xml

该文件大部分内容都已经注释,我们需要添加如下内容:

<profile>
<id>dev</id>
<!-- repositories and pluginRepositories here-->
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>


<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
简介:我们用maven的时候,maven自带的远程中央仓库经常会很慢,还有默认本地仓库是在c盘C:\Users\你的电脑用户账号\.m2\repository,
对于有强迫症的人,总是看的不爽,下面介绍下经验:
 
我的环境:
maven:3.3.9
jdk:1.8_112
intellij idea:2016.3
windows:win10
试验项目:spring boot 1.5.1
 
首先你需要安装maven,我的maven安装的是3.3.9
maven修改远程中央仓库地址:
找到你的maven安装位置,找到conf下的setting.xml,我的位置D:\maven\apache-maven-3.3.9\conf\setting.xml,打开它,
我这里用的sublime3,默认很多都注释了,加入代码:
<profiles>
<profile> <id>dev</id> <!-- repositories and pluginRepositories here--> <repositories> <repository> <id>nexus-aliyun</id> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
在这里我们用的是阿里的maven远程中央仓库,试验过网速杠杠的,这个时候可以去实验下你的maven下载,看是不是阿里的远程仓库地址
maven修改本地仓库地址:
还是在这个setting.xml文件,搜索localRepository:



在下面加入一行<localRepository>D:\down\maven-repository\repository</localRepository>,这里是我自己的maven本地仓库地址,改成自己设置的maven本地仓库地址



然后将setting.xml(maven安装的位置D:\maven\apache-maven-3.3.9\conf\setting.xml),复制一份到你设置的maven本地仓库地址下,
这里的地址是D:\down\maven-repository\repository,配置完成了打开intellij idea,打开file->setting,搜索maven:



将这三处修改,第一处是使用自己安装的maven,这个地方有maven2,maven3,maven3.3.9(自己安装的),选择maven3.3.9
第二处是使用自己配置的放在本地仓库的setting.xml文件
第三处是本地仓库的地址,点击apply,ok
然后可以移动下自己pom.xml中的内容,右下角有下载信息,会显示从http://maven.aliyun.com/nexus/content/groups/public下载到自己定义的仓库地址
 
 开源中国地址:https://Git.oschina.NET/wustxiabin/spring-cloud.git
 github地址:    https://github.com/waterlufei/spring-cloud.git
第二种方式
直接在pom.xml文件中添加:
<project>

 <!--配置远程仓库-->
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<!--阿里的远程仓库-->
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</repository>
</repositories>
</project>


现在,Maven的依赖库查询顺序更改为:
在 Maven 本地资源库中搜索,如果没有找到,进入第 2 步,否则退出。
在 Maven 中央存储库(http://repo1.maven.org/maven2/)搜索,如果没有找到,进入第 3 步,否则退出。
在配置的远程存储库搜索,如果没有找到,提示错误信息,否则退出。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: