Maven精选系列(一):Maven私库搭建及使用

Maven私库搭建及使用


今天博主将为大家分享一下Maven私库搭建及使用,不喜勿喷,如有异议欢迎讨论!

以下所写内容均与以前的文章有联系可以前往博文查看,陈永佳的博客


前言


为什么要使用私库

maven默认去远程中央仓库下载JAR包的,访问国外网络相当慢,如果团队每个人都去下载一遍无疑是网络的浪费,当然也可以添加国内的镜像,如阿里的比较稳定,但如果想添加远程不存在的像第三方公司的JAR包就比较麻烦。

所以,使用私库,第一,开源包只要有一个人下载过其他人就不需要再下载了,直接从私库下载即可。第二,可以用来管理第三方公司的或者远程仓库不存在的JAR包,或者公司不开源的JAR包。

推荐国内稳定的镜像,如阿里的:《Maven系列(一):安装、配置Settings.xml配置文件与使用 》在博主的这篇文章最后的settings.xml文件配置中就用的这个。
http://maven.aliyun.com/nexus/content/groups/public/


nexus下载安装
首先去sonatype官网下载nexus包,要下载开源免费版的OSS版,即Open Source Software。

https://www.sonatype.com/nexus-repository-oss

在这里插入图片描述
下载最新的版本,这里以windows为例进行下载。

下载后点击bin目录中的启动文件即可,默认的端口是8081,访问路径是/,也可以去配置文件中修改,这里以默认。

启动后,打开localhost:8081,nexus默认的用户名是admin/admin123

默认安装有几个仓库,在控制台也可以修改远程仓库的地址,第三方仓库等。

在这里插入图片描述


Maven配置

修改maven主目录conf/setting.xml配置文件

添加nexus认证的用户名和密码配置信息
<servers>
    <server>
          <id>nexus-releases</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>
    <server>
          <id>nexus-snapshots</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>
</servers>
添加mirror镜像
<mirrors>
    <mirror>
          <id>Nexus</id>
          <mirrorOf>*</mirrorOf>
          <name>Nexus</name>
          <url>http://127.0.0.1:8081/repository/maven-public/</url>
     </mirror>
  </mirrors>
添加私库
<profiles>
	<profile>
		<id>Nexus</id>
		<repositories>
			<repository>
				<id>Nexus</id>
				<name>Nexus</name>
				<url>http://127.0.0.1:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>Nexus</id>
				<name>Nexus</name>
				<url>http://127.0.0.1:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
</profiles>
激活私库
<activeProfiles>
    	<activeProfile>Nexus</activeProfile>
</activeProfiles>

发布到私库

在这里插入图片描述

在pom配置文件中添加
<!-- nexus-releases nexus-snapshots与settings.xml中server下的id对应 -->
<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<name>Nexus Releases Repository</name>
		<url>http://localhost:8081/nexus/content/repositories/releases/</url>
	</repository>
	<snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Nexus Snapshots Repository</name>
		<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
	</snapshotRepository>
</distributionManagement>

在项目上使用命令mvn deploy打包就能发布到私库。


到这里Maven私库搭建及使用讲解完毕了,下一篇将为大家讲解Maven如何发布jar包到Nexus私库,请持续关注!


最后

  • 更多参考精彩博文请看这里:《陈永佳的博客》

  • 喜欢博主的小伙伴可以加个关注、点个赞哦,持续更新嘿嘿!

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

陈永佳

你的鼓励将是我创作的最大动力!

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

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

打赏作者

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

抵扣说明:

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

余额充值