Nexus是啥
常见的项目开发中,Maven下载jar包首先会从本地仓库(setting.xml文件定义)根据公司名+项目名+版本号寻找jar包,如果没有,则会去远程仓库,这里远程仓库是指阿里云,腾讯云的国内镜像仓库
,如果没有则会去maven的中央仓库中寻找。这个过程中,其实还有一个部分那就是私服
私服
场景 一
公司中定义了的一个仓库,在局域网中去对整个项目进行管理,特别是针对公司承接隐秘协议或者军队项目时要求全局域网对外隔断只留一个服务器进行联网,私服的作用更为重要。
用户在本地查找本地仓库,若没有jar包,则会去私服中查找,私服定义的是外局域网中能联网的地址
场景二
多模块开发时需要公司内部自定义的jar包协同开发,这时可以通过私服共享jar包
安装部署
下载:
链接:https://pan.baidu.com/s/17OLvfNKgqmJTYLZ7OqZGyA
提取码:sang
两个文件夹,第一个是nexus的工作文件夹(nexus-3.9.0-01),另一个是nexus的配置和仓库目录(sonatype-work)
进入第一个工作文件夹的bin目录中,键入cmd(管理员命令
)
nexus.exe /install Nexus #注册nexus服务
操作成功后,就在windows中注册了Nexus名字的服务,并且开机自启
若不想注册为服务,则继续键入,进行启动 nexus服务端
nexus.exe /run #开启
出现以下窗口,说明启动成功。
仓库配置
找到nexus3.9\sonatype-work\nexus3\etc位置,看到 nexus.properties文件,打开此文件
这里有仓库的访问地址配置,需要修改的话就将前面的 **#
去掉,进行修改,重启服务即可
这里我进行修改成80,http默认端口,随后进行访问:
左上角有Sign in
**登录按钮 ,我们点击登录,账号默认admin,密码admin123
图中最初始有七个仓库,其余是已经创建好的
仓库类型
proxy
代理类型,用于向外进行寻找jar包
hosted
私库类型,用于存放自己写的jar包
group
集合库类型,用于存放上两种类型的jar包
其中hosted类型可以 有三种
RELEASE:发行版本
Snapshot:快照版本,也称不稳定版本
mixed:混合版本,二者都有
建仓库
点击左上角的设置图标按钮
,切换到设置页面,在左侧导航栏中,点击Repositories
,显示出所有的仓库,点击create Repository
按钮
首先创建代理库
其次创建RELEASE的发行版本的库
以及 Snapshot版本的库
最后创建集合库
这里集合库的作用是用于查找jar,排序的顺序,是客户端maven查询的顺序。
客户端配置
首先镜像标签指向私服(集合库的地址
)
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<!--集合库的地址-->
<url>http://localhost:8081/repository/sangGroup/</url>
</mirror>
</mirrors>
配置连接用户
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
配置连接仓库的属性
url都指向私服集合库的地址
<profiles>
<profile>
<id>jdk8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>nexus</id>
<repositories>
<repository>
<!--id与server的id相同-->
<id>nexus</id>
<url>http://localhost:8081/repository/sangGroup/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://localhost:8081/repository/sangGroup/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
最后激活配置
<activeProfiles>
<!--<activeProfile>jdk8</activeProfile>-->
<activeProfile>nexus</activeProfile>
</activeProfiles>
最后在项目的pom.xml
中配置:
<distributionManagement>
<repository>
<id>nexus</id>
<name>Release</name>
<url>私服的发行地址</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshot</name>
<url>私服的快照地址</url>
</snapshotRepository>
</distributionManagement>
这里的id要和server的id相同
运行
将编辑器的maven配置setting文件指向这个文件,然后使用Maven的deploy命令,将打好的jar包发布到私服里面去