在国内使用maven下载jar包非常慢的解决方法

时间:2023-03-08 16:56:58

在国内使用maven下载jar包非常慢的解决方法

1、原因:

很多jar包在国外环境,所以会很慢。

2、解决方法

maven支持镜像环境下载,所以首先找到maven的conf目录中的settings.xml文件,其中有

<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>

将这里的镜像环境改为国内的镜像环境(推荐使用阿里的镜像环境):

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

之后再下载jar包就会快很多了。