Maven学习三 Nexus私服的搭建与使用

一、搭建私服

1.1部署Nexus
1.1.1 Nexus 是Maven仓库管理器,通过nexus可以搭建maven仓库.同时nexus还提供强大的仓库管理功能,构件搜索功能等.Nexus下载地址:https://www.sonatype.com/download-oss-sonatype
在这里插入图片描述
下载并解压得到一下目录结构
在这里插入图片描述
1.1.2 安装
在这里插入图片描述
在这里插入图片描述
cmd进入nexus的bin目录,执行:nexus.bat uninstall
在这里插入图片描述1.1.3 卸载
以管理员身份运行cmd 进入nexus的bin目录,执行:nexus.bat uninstall并查看wendow服务列表 nexus已经被删除.
在这里插入图片描述
1.2 启动Nexus
1.2.1 nexus目录结构
在这里插入图片描述
1.2.2 启动nexus
方法一:cmd进入bin目录,执行nexus.bat start指令
方法二:Window管理直接启动
在这里插入图片描述
正在开启Nexus服务ing
在这里插入图片描述
1.3 认识Nexus
1.3.1 访问nexus
启动后查看nexus配置文件 访问nexus
在这里插入图片描述
根据配置文件信息用浏览器访问http://localhost:8081/nexus/
使用Nexus 内置账户admin/admin123登陆:
点击右上角的Log in,输入账号和密码 登陆
在这里插入图片描述
登录成功,进入主页面
在这里插入图片描述
1.3.2 认识仓库界面
在这里插入图片描述
1.3.3 仓库有四种分类

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

nexus的默认仓库存放在sonatype-work目录中:
在这里插入图片描述
在这里插入图片描述

二、配置Nexus仓库

2.1 配置setting.xml
需要在客户端(即部署maven工程的电脑)配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 .
此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。

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

在这里插入图片描述
在这里插入图片描述
2.2 配置pom.xml文件
配置私服仓库的地址,本公司的自己的jar包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库.

 <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>

在这里插入图片描述
在这里插入图片描述

三、测试

猜你喜欢

转载自blog.csdn.net/weixin_44731123/article/details/88577344
今日推荐