Maven 更换远程仓库地址

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的依赖库查询顺序更改为:

  1. 在 Maven 本地资源库中搜索,如果没有找到,进入第 2 步,否则退出。
  2. 在 Maven 中央存储库(http://repo1.maven.org/maven2/)搜索,如果没有找到,进入第 3 步,否则退出。
  3. 在配置的远程存储库搜索,如果没有找到,提示错误信息,否则退出。


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值