码迷,mamicode.com
首页 > 其他好文 > 详细

maven--私服的搭建(Nexus的使用)

时间:2016-07-17 23:00:29      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

 

Nexus常用功能就是:指定私服的中央地址、将自己的Maven项目指定到私服地址、从私服下载中央库的项目索引、从私服仓库下载依赖组件、将第三方项目jar上传到私服供其他项目组使用。

开启Nexus服务后访问url地址http://localhost:8081/nexus/(推荐使用自己的ip地址),之后登录系统,用户名密码分别是:admin/admin123.

最频繁的就是点击左侧菜单栏的Repositories按钮



group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库; 


hosted 宿主仓库:主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件)  以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)  

proxy 代理仓库:代理公共的远程仓库;   

virtual 虚拟仓库:用于适配 Maven 1;  

一般用到的仓库种类是 hosted、proxy

 

Hosted 仓库常用类型说明:  

releases 内部的模块中 release 模块的发布仓库   

snapshots 发布内部的 SNAPSHOT 模块的仓库   

3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

 

如果构建的 Maven 项目本地仓库没有对应的依赖包,那么就会去 Nexus 私服去下载,   如果Nexus私服也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。   Nexus 私服下载成功后再下载至本地 Maven 库供项目引用。

 

1、设置 proxy 代理仓库(Apache Snapshots/Central/Codehaus Snapshots)准许远程下载, 

其它两个代理库也设置为true

2.Maven 本地库的安装与配置  setting.xml

 

[html] view plain copy
 
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  4.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.     <localRepository>D:/maven/repository</localRepository>  
  7.     <interactiveMode>true</interactiveMode>  
  8.     <offline>false</offline>  
  9.     <pluginGroups>  
  10.         <pluginGroup>org.mortbay.jetty</pluginGroup>  
  11.         <pluginGroup>org.jenkins-ci.tools</pluginGroup>  
  12.     </pluginGroups>  
  13.       
  14.     <!--配置权限,使用默认用户-->  
  15.     <servers>  
  16.         <server>  
  17.             <id>nexus-releases</id>  
  18.             <username>deployment</username>  
  19.             <password>deployment123</password>  
  20.         </server>  
  21.         <server>   
  22.             <id>nexus-snapshots</id>  
  23.             <username>deployment</username>  
  24.             <password>deployment123</password>  
  25.         </server>  
  26.     </servers>  
  27.   
  28.     <mirrors>  
  29.   
  30.     </mirrors>  
  31.   
  32.     <profiles>  
  33.         <profile>  
  34.            <id>nexus</id>  
  35.                 <activation>  
  36.                     <activeByDefault>false</activeByDefault>  
  37.                     <jdk>1.7</jdk>  
  38.                 </activation>  
  39.                 <repositories>  
  40.                     <!-- 私有库地址-->  
  41.                     <repository>  
  42.                         <id>nexus</id>  
  43.                         <url>http://127.0.0.1:1818/nexus/content/groups/public/</url>  
  44.                         <releases>  
  45.                             <enabled>true</enabled>  
  46.                         </releases>  
  47.                         <snapshots>  
  48.                             <enabled>true</enabled>  
  49.                         </snapshots>  
  50.                     </repository>  
  51.                 </repositories>        
  52.                 <pluginRepositories>  
  53.                     <!--插件库地址-->  
  54.                     <pluginRepository>  
  55.                         <id>nexus</id>  
  56.                         <url>http://127.0.0.1:1818/nexus/content/groups/public/</url>  
  57.                         <releases>  
  58.                             <enabled>true</enabled>  
  59.                         </releases>  
  60.                         <snapshots>  
  61.                             <enabled>true</enabled>  
  62.                        </snapshots>  
  63.                     </pluginRepository>  
  64.                 </pluginRepositories>  
  65.             </profile>  
  66.     </profiles>  
  67.       
  68.     <!--激活profile-->  
  69.     <activeProfiles>  
  70.         <activeProfile>nexus</activeProfile>  
  71.     </activeProfiles>  
  72.       
  73. </settings>  
  74.   
  75. <span style="font-family:Arial, Helvetica, sans-serif;"><span style="white-space: normal;">  
  76. </span></span>  

3、将项目发布到私服

pom.xml 添加配置

 

[html] view plain copy
 
 
  1. <distributionManagement>  
  2.     <repository>  
  3.         <id>nexus-releases</id>  
  4.         <name>Nexus Release Repository</name>  
  5.         <url>http://127.0.0.1:1818/nexus/content/repositories/releases/</url>  
  6.     </repository>  
  7.     <snapshotRepository>  
  8.         <id>nexus-snapshots</id>  
  9.         <name>Nexus Snapshot Repository</name>  
  10.         <url>http://127.0.0.1:1818/nexus/content/repositories/snapshots/</url>  
  11.     </snapshotRepository>  
  12. </distributionManagement>  

 

然后运行发布

clean deploy

 

在控制台发布成功后

然后进入到私服上的仓库中,看一下确实存在刚刚发布的项目

 

 

4.上传第三方jar包

 

然后点Select Artifact(s) for Upload按钮选择要上传的jar包,再点 add Arifact

 

最后点 Upload Artifact(s) 

 

上传成功后查看

 

参考

http://blog.csdn.net/xiaoreqing/article/details/51352751

http://www.cnblogs.com/luotaoyeah/p/3817465.html

maven--私服的搭建(Nexus的使用)

标签:

原文地址:http://www.cnblogs.com/hujihon/p/5679617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!