Maven 私服上下载jar包和上传jar包到私服
一、Nexus
执行nexus uninstall命令,卸载。执行nexus.bat start命令,启动
- Nexus 是Maven仓库管理器,通过nexus可以搭建maven仓库,同时nexus还提供强大的仓库管理功能,构件搜索功能等。
下载地址:https://www.sonatype.com/oss-thank-you-win64.zip,解压后进入bin目录,执行nexus install,进行安装
![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM4MDY4ODEy_size_16_color_FFFFFF_t_70][]
安装成功,可以在计算机管理中看到nexus服务进程
![20181222073248282.png][]
- 启动后,本地访问http://localhost:8081/nexus/ 登陆用户和密码默认为:admin/admin123
4.登陆成功后页面
- hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
- proxy,代理仓库,用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件。
- group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组。
- virtual(虚拟):兼容Maven1 版本的jar或者插件
二、从私服上下载jar包
通常在企业中会在局域网内部署一台私服服务器,有了私服本地项目首先去本地仓库找jar,如果没有找到则连接私服从私服下载jar包,如果私服没有jar包私服同时作为代理服务器从中央仓库下载jar包,一方面由私服对公司项目的依赖jar包统一管理,一方面提高下载速度,项目连接私服下载jar包的速度要比项目连接中央仓库的速度快的多。
在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库。
在setting中
标签中拷贝如下内容
- 仓库组
在maven中setting.xml中配置仓库
dev
nexus
http://localhost:8081/nexus/content/groups/public/
true
true
public
Public Repositories
http://localhost:8081/nexus/content/groups/public/
使用profile定义仓库需要激活才可生效。
dev
settiings.xml中配置如下:在
标签外配置
三、上传jar包到私服
1.配置setting.xml
修改 maven中settings.xml 文件,配置连接私服的用户和密码 。
此用户名和密码用于私服校验,因为私服需要知道上传的账号和密码 是否和私服中的账号和密码一致。![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM4MDY4ODEy_size_16_color_FFFFFF_t_70 4][]
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
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>
注意:pom.xml这里
和 settings.xml 配置 对应! 此处的id分别为releases和snapshots 3.将项目dao工程打成jar包发布到私服
启动nexus后,对dao工程或者Service执行deploy命令
执行成功后:
还没有评论,来说两句吧...