Nexus搭建Maven私服
使用背景:公司访问外网限制,项目组大部分人员不能访问maven的center repository,因此在局域网里找一台有外网权限的机器,搭建nenux私服,然后开发人员连接到这台私服上。
环境:nexus-2.1.1、maven-3.04,jdk-1.6.0 一、使用admin用户登陆nexus 二、为nexus配置代理服务器 由于这台机器需要通过代理才能访问外网,所以首先要配置代理服务器,在Adminstrain->Server进行配置 配置之后,nexus才能连上center repository,如果私服所在机器可以直接上外网,则可以省略这一步。 nexus可以配置3种类型的仓库:proxy,hosted,group: 2.1)、proxy是远程仓库代理,可以配置center repository的proxy,相当于中转的作用。 2.2)、hosted是宿主仓库,用户可以吧自己的一些构件,deploy到hosted中,在center respository中获取不到,就需要手工上传到hosted里。 2.3)、group仓库组,将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了。
三、配置仓库: 3.1)、配置Center Resposity的proxy 3.2)、配置hosted repository: 一般配置3个hosted repository分别:3rd party,Snapshots,Releases分别用来保存第三方jar,项目组内部的快照,项目组内部的发布版。 3.3)、配置group repository: group其实是一个虚拟的仓库,通过实体仓库进行聚合,对外暴露一个统一的地址。
四、配置用户密码:
Security->Users
五、在setting.xml文件中配置Nexus仓库:
5.1)、maven提供了profile来配置仓库信息
myprofile
central
http://central
true
true
central
http://central
true
false
5.2)、激活profile
myprofile
5.3)、配置镜像:
nexus
http://127.0.0.1:7788/nexus/content/groups/public/
*
六、配置maven项目的pom文件:
<!-- 配置部署的远程仓库 -->
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus distribution snapshot repository</name>
<url>http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
七、eclipse中的设置 在Preferences-->Maven-->User Settings中,点击Update Settings,加载刚才我们对settings.xml的更改。 然后在Maven Repositories视图里,可以看到仓库的情况