nexus 搭建私有maven仓库
nexus 搭建私有maven仓库
一.nexus的安装和配置
1.下载安装nexus
官网:https://www.sonatype.com/ 下载完成后,解压后直接使用2.密码和端口修改:
修改 D:\nexus\nexus-3.19.1-01\etc\nexus-default.properties
其中 nexus-context-path=/ht 时,访问路径: http://172.18.11.135:8081/ht/
3.启动nexus
3.1 启动方式一

cmd 命令进入 D:\nexus\nexus-3.19.1-01\bin
执行 nexus.exe /run 启动nexus服务3.2 启动方式二
nexus配置为系统服务:
cmd命令行
cd D:\nexus\nexus-3.19.1-01\bin
执行 nexus.exe /install nexus
进入windows服务 选择 nexus 点击启动
4.访问和登录
未登陆状态下页面展示
浏览器输入: http://172.18.11.135:8081/
点击 : sign in 登录
用户名: admin 密码:查看 D:\nexus\sonatype-work\nexus3\admin.password
依据提示修改密码
如上图所示,type类型仅有三种状态:
proxy : 远程仓库代理,即配置外网的maven远程仓库地址的资源库,本地若找不到,会通过代理资源库中的地址,
找到远程仓库,从远程仓库中下载所需要的jar
hosted: 宿主仓库,公司自己开发的jar包 或者 (本地资源库,从远程仓库中下不到,手动找到jar下载)
放在托管资源库中,交给nexus统一管理。
group: 仓库组,包含代理仓库和宿主仓库。把代理资源库和托管资源库统一配置到组资源库中,组资源库作为一个唯一的public提 供给所有人使用5.nexus 说明
6.存储目录设置

点击repository栏下的blob stores,填写对应的目录名称。
二.jar包上传

1 maven配置(conf/settings.xml)
如下节点中配置如下内容
<servers>
<!-- conf private maven repository in there,server可以配置多个-->
<server>
<id>testnexus</id>
<!-- nexus登录的用户名和密码-->
<username>admin</username>
<password>123456</password>
</server>
</servers>2 创建repositories仓库
创建的仓库类型一定要是hosted类型的,否则无法上传。
Snapshot库发布的版本必须以SNAPSHOT结尾。
release发布的版本不能以SNAPSHOT结尾。
3 执行mvn deploy命令上传
cmd命令 后执行 下列mvn deploy命令
mvn deploy:deploy-file -DgroupId=com.alibaba.druid -DartifactId=druid-1.1.0 -Dversion=1.1.0 -Dpackaging=jar -Dfile=D:\maven\apache-maven-3.6.3-bin\apache-maven-3.6.3\repository2\com\alibaba\druid\1.1.0\druid-1.1.0.jar -Durl=http://172.18.11.187:9999/repository/testnexus -DrepositoryId=testnexus
DgroupId: 可自定义名称
DartifactId: 可自定义名称
Dversion: jar版本信息
Dpackaging: 类型
Dfile: jar包绝对路径
Durl: 私服仓库位置
DrepositoryId : 私服库Id,引用settings.xml配置文件中server标签中id
4 验证成功


5 上传自开发jar包
接 上述 5.1 、 5.2 后
新建文件夹,将 项目build成功的jar包放到该文件夹中,执行
mvn deploy:deploy-file -DgroupId=ht.gov.k8s -DartifactId=SpringK8s -Dversion=0.0.1 -Dpackaging=jar -Dfile=F:\SpringK8s-0.0.1-SNAPSHOT.jar -Durl=http://172.18.11.187:9999/repository/testnexus -DrepositoryId=testnexus
DgroupId: 可自定义名称
DartifactId: 可自定义名称
Dversion: jar版本信息
Dpackaging: 类型
Dfile: jar包绝对路径
Durl: 私服仓库位置
DrepositoryId : 私服库Id,引用settings.xml配置文件中server标签中id6.上传注意事项

详细解释:
如果安装的jar和pom是位于本地repository目录下,当使用【mvn deploy:deploy-file】 命令上传就会出错
(Cannot deploy artifact from the local repository…),
解决方法:将要安装的jar和pom copy到其它目录再安装,只要不在本地仓库目录都可以.7.使用界面上传

选择对应的jar包文件,并填写 group id,artifact id ,version 三.自开发jar导出方法

操作步骤:点击项目--> export --> jar file --> 存储路径 --> finish注意: 使用maven install 打包无法使用
四.jar包下载使用

在springboot 项目中 添加项目依赖,就可以完成私有包下载
<dependency>
<groupId>ht.gov.k8s</groupId>
<artifactId>SpringK8s</artifactId>
<version>0.0.2</version>
</dependency>
若无法正常下载,可手动点击path路径,进行下载
文章标题:nexus 搭建私有maven仓库
发布时间:2021-08-23, 20:11:40
最后更新:2021-08-23, 20:11:01