nexus私服使用介绍

搭建私服环境

nexus的安装

nexus安装包:点击传送

在这里插入图片描述

以管理员身份打开命令行,切换到【nexus.bat所在的目录】,执行安装命令

nexus.bat install

nexus的卸载

以管理员身份打开命令行,切换到【nexus.bat所在的目录】,执行卸载命令

nexus.bat uninstall

nexus的启动

方式一

以管理员身份打开命令行,切换到【nexus.bat所在的目录】,执行启动nexus命令

nexus.bat start

方式二

打开win10的【服务】,找到nexus,启动。

nexus的配置文件nexus.properties介绍

# Jetty section
application-port=8081 # nexus 的访问端口配置
application-host=0.0.0.0 # nexus 主机监听配置(不用修改)
nexus-webapp=${bundleBasedir}/nexus # nexus 工程目录
nexus-webapp-context-path=/nexus # nexus 的 web 访问路径
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus # nexus 仓库目录
runtime=${bundleBasedir}/nexus/WEB-INF # nexus 运行程序目录

nexus私服介绍

nexus默认主页:http://localhost:8081/nexus/

nexus内置账户与密码:账号:admin,密码:admin123

nexus仓库类型

  • hosted,宿主仓库,部署自己的 jar 到这个类型的仓库,包括 releases 和 snapshot 两部分,Releases 公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
  • proxy,代理仓库,用于代理远程的公共仓库,如 maven 中央仓库,用户连接私服,私服自动去中央仓库下载 jar 包或者插件。
  • group,仓库组,用来合并多个 hosted/proxy 仓库,通常我们配置自己的 maven 连接仓库组。
  • virtual(虚拟),Maven1 版本的 jar 或者插件

私服的应用

上传jar包到私服

需求:将ssm_dao上传到私服

配置步骤

(1)修改maven的setting.xml文件,配置连接私服的用户名和密码。将下面代码配置到 <servers>标签内。

	<server>
		 <id>releases</id>
		 <username>admin</username>
		 <password>admin123</password>
	</server>
	<server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	<server>
		<id>thirdparty</id>
		<username>admin</username>
		<password>admin123</password>
	</server>

上面代码中releases(发行版),snapshots(测试版),thirdparty(上传第三方jar包到私服)分别对应到私服中

在这里插入图片描述

(2)配置ssm_dao项目的pom.xml(如果有多个模块,可以将distributionManagement标签配置在父工程的pom.xml,这样发布的时候,子模块的jar包都会被发布到私服,如果有web工程的子模块,需要单独配置distributionManagement标签)

配置私服仓库的地址,本公司的自己的jar 包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库(如下图中说明),如果版本为release 则上传到私服的release 仓库,如果版本为snapshot 则上传到私服的snapshot 仓库。

注意:pom.xml 这里<id>和settings.xml 配置<id> 对应!,名称一致才能正确发布到仓库中。

<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

在这里插入图片描述

测试

找到maven窗口,执行deploy命令

在这里插入图片描述

可以访问私服主页,打开仓库,可以看见刚刚发布的ssm_dao的jar包。

在这里插入图片描述

从私服下载jar包到本地仓库

需求:将ssm_dao的jar包从私服下载到maven仓库。

没有配置nexus 之前,如果本地仓库没有,去中央仓库下载,通常在企业中会在局域网内部署一台私服服务器,有了私服本地项目首先去本地仓库找jar,如果没有找到则连接私服从私服下载jar 包,如果私服没有jar 包私服同时作为代理服务器从中央仓库下载jar 包,这样做的好处是一方面由私服对公司项目的依赖jar 包统一管理,一方面提高下载速度,项目连接私服下载jar 包的速度要比项目连接中央仓库的速度快的多。

本例子测试从私服下载ssm_dao 工程jar 包。

管理仓库组

nexus中包括很多仓库,hosted中存放的是企业自己发布的jar包及第三方公司的jar包,proxy 中存放的是中央仓库的jar,为了方便从私服下载jar 包可以将多个仓库组成一个仓库组,每个工程需要连接私服的仓库组下载jar 包。

  • central:代理仓库,代理中央仓库

  • releases:本地仓库,存储 releases构件。

  • snapshots:本地仓库,存储 snapshots构件。

  • thirdparty:第三方jar包的仓库

  • public:仓库组

在这里插入图片描述

在setting.xml 中配置仓库

(1)在客户端的setting.xml 中配置私服的仓库,由于setting.xml 中没有repositories 的配置标签需要使用profile标签 定义仓库。

<profile> 
		<!--profile 的 id-->
		<id>dev</id> 
		 <repositories> 
			 <repository> 
			<!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
			 <id>nexus</id> 
			<!--仓库地址,即 nexus 仓库组的地址-->
			 <url>http://localhost:8081/nexus/content/groups/public/</url> 
			<!--是否下载 releases 构件-->
			 <releases> 
			 <enabled>true</enabled> 
			 </releases> 
			<!--是否下载 snapshots 构件-->
			 <snapshots> 
			 <enabled>true</enabled> 
			 </snapshots> 
			 </repository> 
		 </repositories> 
		<pluginRepositories> 
		 <!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
		 <pluginRepository> 
		 <!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
		 <id>public</id> 
		 <name>Public Repositories</name> 
		 <url>http://localhost:8081/nexus/content/groups/public/</url> 
		 </pluginRepository> 
		 </pluginRepositories> 
	 </profile>

(2)使用profile 定义仓库需要激活才可生效。在maven的配置文件setting.xml中添加激活下载的标签<activeProfiles>dev必须和上面配置的id的的值一致。

 <activeProfiles>
 	<activeProfile>dev</activeProfile>
 </activeProfiles>

测试

由于之前deploy过ssm_dao,这里先将它从maven仓库中删除。

由于ssm_service依赖ssm_dao,这里点击ssm_service将complie后,在本地maven仓库已经没有ssm_dao,所以会从私服下载ssm_dao,如图。

在这里插入图片描述

在这里插入图片描述

第三方jar的安装

安装第三方jar包到本地仓库

方式一:进入jar包所在目录运行cmd

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dfile=fastjson-1.1.37.jar -Dpackaging=jar

方式二:打开cmd直接运行

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=C:\my_java\授课资料\资料:maven【高级】\安装第三方jar包\fastjson-1.1.37.jar

注意:方式二需要指定第三方jar包所在路径

安装第三方jar包到私服

在settings配置文件中<servers>标签中添加登录私服第三方登录信息

<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>

方式一:进入jar包所在目录运行cmd

mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

方式二:打开cmd直接运行

mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=C:\my_java\授课资料\资料:maven【高级】\安装第三方jar包\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

注意:方式二需要指定第三方jar包所在路径

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值