Nexus搭建Maven私服以及两者之间的关联

搭建Maven私服Nexus以及两者之间的关联


安装Nexus

1. Nexus介绍
  • nexus是一个强大的maven仓库管理器,它极大的简化了本地内部仓库的维护和外部仓库的访问。
  • nexus是一套开箱即用的系统不需要数据库,它使用文件系统加Lucene来组织数据。
    nexus使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过IDEA和Eclipse集成使用。
  • exus支持webDAV与LDAP安全身份认证。
  • nexus提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,占用较少的内存,基于简单文件系统而非数据库。
2.下载地址
  • https://www.sonatype.com/download-nexus-repo-oss 在这里插入图片描述
  • 因为Nexus Repository Manager 仓库管理有2个版本,专业版和oss版,oss版是免费的,专业版是收费的,我们使用oss版。
3. 安装
  • 因为下载下来的文件是nexus解压版的,所以直接解压到指定文件夹即可;
    在这里插入图片描述
  • 配置环境变量
    进入环境变量界面
    在这里插入图片描述
    然后找到Path在最后写入%NEXUS_HOME%\bin(注意前面有没有分号;);
  • cmd进入到指定文件夹\bin目录下,执行命令:nexus.exe /run ;
  • 打开http://localhost:8081/;
  • 如果需要修改8081端口号8088,则在nexus文件夹下找到etc\nexus-default.properties文件打开修改application-port;
    在这里插入图片描述
  • 如果需要修改其他配置,请自行百度,这里就不一一介绍了。

Maven与Nexus的关联

1. Maven下的conf\setting.xml配置
  • servers配置
    在setting文件找到servers节点,在server节点下第一行加入以下代码:
<server>
	<!--nexus发布版-->
	<id>nexus-snapshots</id>
	<!--nexus账户-->
	<username>admin</username>
	<!--nexus账户密码-->
	<password>admin</password>
</server>
<server>
	<!--nexus快照版-->
	<id>nexus-snapshots</id>
	<!--nexus账户-->
	<username>admin</username>
	<!--nexus账户密码-->
	<password>admin</password>
</server>
  • mirrors配置
    在setting.xml文件中找到mirrors节点,在mirrors节点下第一行加入以下代码:
<mirror>
	<id>local private nexus</id>
	 <mirrorOf>*</mirrorOf>
	<name>nexus-value</name>
	<url>http://localhost:8081/repository/maven-public/</url>
 </mirror>
2. 本地项目上传配置
  • 找到项目中的pom.xml,将加入以下代码:
<!--repositories是远程下载项目中依赖的仓库地址,可以设置成阿里云的镜像,如果自己的私库比较全,也可以设置成自己的,个数没限制,前后顺序有限制-->
<!--repository下的name与maven settings中mirror中的id一致-->
<repositories>
	<repository>
		<id>nexus</id>
		<name>local private nexus</name>
		<url>http://localhost:8081/repository/maven-public/</url>
		<releases><enabled>true</enabled></releases>
		<snapshots><enabled>true</enabled></snapshots>
	</repository>
</repositories>
<!--pluginRepositories是远程下载项目中插件的仓库地址,可以设置成阿里云的镜像,如果自己的私库比较全,也可以设置成自己的,个数没限制,前后顺序有限制-->
<!--pluginRepository下的name与maven settings中mirror中的id一致-->
<pluginRepositories>
	<pluginRepository>
		<id>nexus</id>
		<name>local private nexus</name>
		<url>http://localhost:8081/repository/maven-public/</url>
		<releases><enabled>true</enabled></releases>
		<snapshots><enabled>true</enabled></snapshots>
	</pluginRepository>
</pluginRepositories>
<!--distributionManagement是将本地项目打包之后上传nexus的地址,其中repository是发布版地址,snapshotRepository是快照版地址-->
<!--repository和snapshotRepository下的id必须与maven settings中server中的id一样,不让上传不上去-->
<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<name>Releases</name>
		<url>http://localhost:8081/repository/maven-releases/</url>
	</repository>
	<snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Snapshots</name>
		<url>http://localhost:8081/repository/maven-snapshots/</url>
	</snapshotRepository>
</distributionManagement>
  • 直接执行maven命令进行打包上传
    mvn clean install deploy -Dmaven.skip.test=true
  • 上传成功
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值