nexus私服

Nexus私服配置

二、 Nexus安装与启动

1、  解压

nexus私服

2、  配置jdk环境变量(如果java的环境变量之前没有配置的)

在解压后nexus-2.14.5-02文件\bin\jsw\conf 里的wrapper.conf配置

nexus私服

nexus私服

3、  dos启动私服 nexus

nexus私服

         继续后输入nexusinstall 服务里安装了nexus

第一种可以在服务内启动

第二种dos输入nexus start启动

4、  访问私服默认端口:8081

浏览器输入localhost:8081/nexus进入私服

nexus私服

Log In 登入

nexus私服

默认  用户名:admin  密码:admin123

 

二、 将项目发布到私服

1、 配置

第一步: 需要在客户端即部署 dao 工程的电脑上配置maven 环境,并修改 settings.xml 文件,配置连接私服的用户和密码。

此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。

<server>

 <id>releases</id>

 <username>deployment</username>

 <password> deployment123</password>

 </server>

 <server>

 <id>snapshots</id>

 <username> deployment </username>

 <password> deployment123</password>

 </server>

 

如果之前setting设置连接的aliyun仓库删掉

nexus私服

releases 连接发布版本项目仓库

snapshots连接测试版本项目仓库

 

第二步: 配置父模块项目 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>

nexus私服

注意:pom.xml 这里<id> 和 settings.xml 配置 <id> 对应!

 

第三步:将项目工程打成 jar 包发布到私服:

1、首先启动 nexus

2、对工程执行 deploy命令

根据本项目pom.xml中version定义决定发布到哪个仓库,如果version定义为snapshot,执行 deploy 后查看 nexus 的 snapshot 仓库,如果 version 定义为 release 则项目将发布到 nexus的 release 仓库

nexus私服

三、 从私服下载 jar 包

第一步:管理仓库组

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

 nexus私服

上图中仓库组包括了本地仓库、代理仓库等。

 

第二步:在 setting.xml 中配置仓库

在客户端的 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>

使用 profile 定义仓库需要**才可生效。

<activeProfiles>

 <activeProfile>dev</activeProfile>

 </activeProfiles>

nexus私服

 

第二步:在 web子模块下的pom.xml 中配置

<repositories>

 <repository>

 <releases>

 <enabled>true</enabled> 

 

 </releases>

 <snapshots>

 <enabled>true</enabled>

 </snapshots>

 <id>public</id>

 <name>Public Repositories</name>

 <url>http://localhost:8081/nexus/content/groups/public/</url>

 </repository>

 <repository>

 <snapshots>

 <enabled>false</enabled>

 </snapshots>

 <id>central</id>

 <name>Central Repository</name>

 <url>https://repo.maven.apache.org/maven2</url>

 </repository>

 </repositories>

 <pluginRepositories>

 <pluginRepository>

 <id>public</id>

 <name>Public Repositories</name>

 <url>http://localhost:8081/nexus/content/groups/public/</url>

 </pluginRepository>

 <pluginRepository>

 <releases>

 <updatePolicy>never</updatePolicy>

 </releases>

 <snapshots>

 <enabled>false</enabled>

 </snapshots>

 <id>central</id>

 <name>Central Repository</name>

 <url>https://repo.maven.apache.org/maven2</url>

 </pluginRepository>

 </pluginRepositories>

四、 私服索引维护

辅助材料indexer文件夹

nexus私服

打开文件夹里的jar.txt

nexus私服

Jar打开内容

nexus私服

将jar里内容复制到dos系统

nexus私服

将解压好的内容放入E:\sonatype-work\nexus\indexer\central-ctx

nexus私服

nexus私服