Maven 镜像设置

24 篇文章 0 订阅
19 篇文章 1 订阅


虽然项目中一直使 Maven 但是从接手到现在,都没动过它。完全是之前配置好的。

然而用的官方的软件仓库,那个速度实再让人求生不能。趁着放假在家,还是折腾一下吧。

这么明显的问题,肯定早就已经案例满地了。肯定拿来就用嘛。于是上网找了个,发现对于新手来说,还是有坑的。

Eclipse

1、首先我 Eclipse 自带的 Maven 没有什么 setting.xml

C:\Users\jerry\.m2\settings.xml 这个位置是空的。
要自己手动创建它,再打开就会看到多个了 open file
这里写图片描述
然后打开,把 阿里爸爸的配置粘进去,保存。然后记得点一下边上的 Update Settings 按钮

<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<mirrors>
		<mirror>
			<id>alimaven</id>
			<name>aliyun maven</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>
</settings>

如果有兴趣,还可以把 本地的 C:\Users\{user}\.m2\repository 目录换一下,毕竟放到 C 盘不太安心。

<localRepository>E:\Develop\repository</localRepository>

然后保存,你会发现,原来乌龟爬的速度,变成一瞬间就更新完了。我靠,我还以为是幻觉呢~~~不过倒回来想想,那么小的文件,这速度才是正常的嘛。

2、添加依赖

官方仓库 mvnrepository搜下速度慢,但是搜下 Jar 包,以及XML片段还是很方便的。
以 org.apache.ibatis.io.Resources 这个类为例。
首先要知道它在哪个Jar包,用 findjar 搜。
得知 Jar 包名:ibatis-sqlmap
回到 官方仓库 mvnrepositoryibatis-sqlmap 然后点开所需的版本,就会看到下面:
这里写图片描述

<!-- https://mvnrepository.com/artifact/org.apache.ibatis/ibatis-sqlmap -->
<dependency>
    <groupId>org.apache.ibatis</groupId>
    <artifactId>ibatis-sqlmap</artifactId>
    <version>3.0-beta-10</version>
</dependency>

粘贴到 pom.xml 的 dependencies 节点中即可。
当然按照亲疏远近排版一下,别一通乱贴才是好习惯。

Idea

设置 maven 配置文件位置

在这里插入图片描述

打开 maven 设置文件

在这里插入图片描述

添加阿里云

C:\Users\jerry\.m2\settings.xml

  <mirrors>
        <!-- 镜内服务器		-->
        <mirror>
        	<!-- 此镜像的唯一标识,用来区分不同的mirror -->
            <id>nexus-aliyun</id>
            <!-- 创建哪个仓库的镜像 -->
            <mirrorOf>central</mirrorOf>
            <!-- 镜像名称 -->
            <name>Nexus aliyun</name>
            <!-- 镜像URL -->
            <url>http://maven.aliyun.com/nexus/content/repositories/central</url>
        </mirror>
  </mirrors>

在项目POM中设置仓库

E:\learnspace\springboot_demo_aop\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>

依赖搜索

阿里云 - 公共代理库 https://help.aliyun.com/document_detail/102512.html

http://search.maven.org/
https://repository.sonatype.org/
https://maven.aliyun.com/mvn/search 优先用阿里,速度好些

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笑虾

多情黯叹痴情癫。情癫苦笑多情难

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值