私服的搭建及不说了csdn很多文章,我来讲讲配置,这还是2015年的作品翻出来的
Nexus操作手册
一、Nexus私服安装
第一步:下载nexus.war包,然后拷贝到tomcat下的webapps目录中,第二步:启动tomcat
第三步:访问http://localhost:8080/nexus/显示如下:
第四步:点击右上角“log in” ,输入username:admin 和Password:admin123登录
第五步:登录成功
第六步:点击Views/Repositories 中Repositories
Nexus内置仓库说明:
(1)Central:该仓库代理Maven中央仓库,其策略为Release,因此只会下载和缓存中央仓库中的发布版本构件。
(2)Releases:这是一个策略为Release的宿主类型仓库,用来部署组织内部的正式发布版本构件,更加严格。
(3)Snapshots:这是一个策略为Snapshot的宿主类型仓库,用来部署组织内部的开发版本构件。
(4)3rd party:这是一个策略为Release的宿主类型仓库,用来部署无法从互联网中央仓库获得的第三方发布版本构件,比如IBM或者oracle的一些jar包(例如classe12.jar),由于受到商业版权的限制,不允许在中央仓库出现,如果想让这些包在私服上进行管理,就需要第三方的仓库。
(5)Public Repositories:该仓库组将上述所有策略为Release的仓库聚合,并通过一致的地址提供服务。
第七步:创建宿主目录和代理仓库
Hosted:本地仓库(当前服务器),通常我们会部署自己的构件到这一类型的仓库。
包括3rd party仓库,Releases仓库,Snapshots仓库
Proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
Group:仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组。如果要将自己创建的仓库构建,通过私服也要查询出来,可以将自己创建的仓库构建部署到仓库组中(这里添加了两个b2b)。
Virtual:虚拟仓库,已经不用!
注意:Hosted允许用户自己上传jar包,并可以下载使用
Proxy不允许用户自己上传jar包,只能从中央仓库下载
第八步:创建仓库组
点击Public Repositories仓库,在Configurations栏中选取需要合并的仓库,点击箭头加到左边保存即可
第九步:下载Index索引并进行构建搜索(GAV搜索)
配置文件和顺序:(全局)MAVEN_HOME/conf/setting.xmlà本地setting.xmlàproject(pom)
第十步:配置所有构建均从私服下载,setting.xml中配置如下:
<settings>
<mirrors>
<mirror>
<!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
<id>nexus</id>
<!-- 拦截下来所有的仓库做镜像 -->
<mirrorOf>*</mirrorOf>
<url>http://localhost:9090/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--所有请求均通过镜像,配置一个假的中央仓库地址,重写中央仓库的路径地址 -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 激活profiles -->
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
其中:
(1)mirror配置:表示私服仓库组的路径
(2)为什么配置一个假的中央仓库地址,重写中央仓库的路径地址
保证不能从中央仓库地址,只能从私服的地址下载。
第十一步:Nexus的访问权限控制,setting.xml中配置如下:
<!-- 设置发布时的用户名 -->
<servers>
<!-- releases和snapshots表示是上传到正式仓库还是开发仓库 -->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
第十二步:部署构建到Nexus,包含Release和Snapshot, 在父项目(Parent)根目录中pom.xml中配置:
<!-- 依赖包发布到私服,将开发的包上传到宿主仓库-->
<distributionManagement>
<!-- 上传到宿主仓库的releases -->
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:9090/nexus/content/repositories/releases/</url>
</repository>
<!-- 上传到宿主仓库的snapshots -->
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:9090/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
第十三步:将自己开发的仓库发布到私服上去,选择parent项目中的pom.xml。执行clean deploy。大家可以看到我们开发的项目已经上传到了私服上。
思考:大家将parent、web、hello、helloFriend、MakeFriend的工程中所有的SNAPSHOT改成Release,大家看看是什么效果?结果就是会在Releases的仓库中看到我们的项目包。
<groupId>com.automic.maven</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-Release</version>
<packaging>pom</packaging>
二、在私服上创建自己的仓库,并配置用户,角色,权限(附加,了解知识.后来修改成waterResoure)
第一步:建立自己的仓库
创建一个本地的主机仓库:
在配置中配置以下信息
第二步:配置权限
添加“研发六部”的权限:
配置:
第三步:添加角色
添加“研发六部”的角色
配置下面的信息:
选择权限、
第四步:添加用户
点击添加用户
配置:
选择需要添加的角色
第六步:部署构建到Nexus,包含Release和Snapshot, 在父项目(Parent)根目录中pom.xml中配置:
<distributionManagement>
<repository>
<id>WaterResource</id>
<name>WaterResource</name>
<url>http://localhost:9090/nexus/content/repositories/WaterResource/</url>
</repository>
</distributionManagement>
第七步:Nexus的访问权限控制,在setting.xml中配置如下:
<!-- 设置发布时的用户名 -->
<servers>
<server>
<id>WaterResource</id>
<username>WaterResource</username>
<password>WaterResource</password>
</server>
</servers>
第八步:将自己开发的项目Hello,HelloFriend,MakeFriend,Parent,Web发布到WaterResource的仓库中,使用命令clean deploy
注意:如果发现没有部署成功Web,应该去掉Web中的pom.xml中红色部分的配置:
<build>
<finalName>web</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<home>D:/apache-tomcat-7.0.27</home>
</container>
<configuration>
<type>existing</type>
<home>D:/apache-tomcat-7.0.27</home>
</configuration>
</configuration>
<executions>
<execution>
<id>cargo-run</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
三:如何将自己的jar上传到私服中的第三方仓库
第一步:选择3rd party,会看到下方的Artifact Upload
第二步:完成配置:
第三步:点击Add Artifact,最后点击upload Artifact(s)
第四步:查看上传的jar包
第五步:查看上传的jar包的坐标:
完成classes.jar的包下载到本地仓库:
第一步:配置所有构建均从私服下载,在setting.xml中配置(前面已经配置完毕):
第二步:将jar包的坐标放置到项目parent中的pom.xml
第三步:保存parent项目中的pom.xml,可以在本地仓库中看到jar包,这是从私服上下载到本地仓库的包。
同时发现Hello项目中已经存在junit10.4.jar