两种方式解决maven下载慢的问题

Maven会先在本地仓库里查找需要的构件(理解为jar包),如果找不到,在不进行任何配置的情况下,会去Maven的中央仓库去下载,因为Maven的中央仓库在国外,路比较远,所以下载速度比较慢。解决方案就是配置离你近的仓库,方法比较多,对于一般使用来讲,主要有两种方案。

第一种方案:使用阿里云的镜像站点

这种配置在所有的Maven项目中都生效。在settings.xml的mirrors标签下添加如下内容:settings.xml在${M2_HOME}/conf/下

<mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

第二种方案:配置远程阿里云仓库

这种配置只在配置的项目中生效,其他的Maven项目不生效。在项目的pom文件中添加如下内容

<repository>
    <id>aliyun</id>
    <name>aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <layout>default</layout>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>

这两种方案的本质就是在下载Maven构件的时候,不去中央仓库下载,而是去阿里云仓库下载。这样就大大提高了下载的速度。第一种配置方式是全局配置,配置之后,可以在所有的Maven项目中生效,建议都去做下这个操作。第二种方式是在项目中进行配置,很显然只在项目范围内生效,你的项目如果要发布,建议加上比较好。

如果在企业环境中,你作为项目的管理者,建议搭建Maven的私服,在项目开发中,就可以使用第二种方式配置,只是配置的URL是你的私服的地址,这样速度会更快,并且你们公司的所有的构件都可以放到私服上。

更换Ubuntu的apt源

解决Ubuntu下载软件慢的问题,也就是更换apt的源为阿里的镜像。

把/etc/apt/sources.list 文件的内容换成下面的,然后执行 sudo apt-get update,之后就可以飞快的下载了。

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值