Maven零散笔记——配置Nexus

应朋友需要,整理Nexus相关资料,做一些简要整理,方便他人!Maven零散笔记——配置Nexus

Nexus 用于建立本地MVN仓库,我就不在这里罗嗦了。
当前的版本为2.0.6,可以直接下载 tar包,解压后进行简单配置就可以使用了!

闲言少叙,命令走起~

Shell代码  Maven零散笔记——配置Nexus
  1. #下载  
  2. wget http://www.sonatype.org/downloads/nexus-2.0 . 6 -bundle.tar.gz  
  3.   
  4. #解压  
  5. tar zxvf nexus-2.0 . 6 -bundle.tar.gz  
  6.   
  7. #做软链接,方便操作,应个人需要  
  8. ln -s nexus-2.0 . 6  nexus  


解压后,应该获得如下目录结构:

  • nexus-2.0.6 是nexus服务主目录
  • sonatype-work 是真正的仓库,同时包含了nexus的配置,如定时任务、用户配置等


Maven零散笔记——配置Nexus

nexus支持如下命令:

引用
nexus { console | start | stop | restart | status | dump }



端口配置在nexus/conf/nexus.properties 文件中,文件如下:

Properties代码  Maven零散笔记——配置Nexus
  1. # Sonatype Nexus  
  2. # ==============  
  3. # This is the most basic configuration of Nexus.  
  4.   
  5. # Jetty section  
  6. application-port=8081   
  7. application-host=0.0 . 0.0   
  8. nexus-webapp=${bundleBasedir}/nexus  
  9. nexus-webapp-context-path=/nexus  
  10.   
  11. # Nexus section  
  12. nexus-work=${bundleBasedir}/../sonatype-work/nexus  
  13. runtime=${bundleBasedir}/nexus/WEB-INF  
  14. pr.encryptor.publicKeyPath=/apr/public-key.txt  


如果你需要修改nexus服务端口或IP,可对于修改。

启动后,如下界面:
Maven零散笔记——配置Nexus
默认管理员帐号:
用户名:admin
密码:admin123

注:最好现在就修改管理员密码! ,nexus已经做得很人性化了,我就介绍如何修改密码了!

通常可以在maven工具里找到的包,也可以在这里找到:
Maven零散笔记——配置Nexus

当然,为了让你的nexus更加智能,需要做一些定时任务,譬如定期下载索引,加快本地mvn检索速度。
以建立定期下载索引为例,在Administration 选项中找到Scheduled Tasks ,在窗口页面点击Add ,进行配置:
Maven零散笔记——配置Nexus

除此之外,我还经常要添加一些额外的jar到nexus中,譬如我要追加BC的组件包到nexus中,供团队其他开发成员使用。
找到View/Repositories ,打开Repositories 窗口,选择3rd party ,进行如下配置:
Maven零散笔记——配置Nexus
之后,就可以在这里找到该jar了:
Maven零散笔记——配置Nexus

为了让你的maven默认访问你的私服,需要配置settings.xml:

Xml代码  Maven零散笔记——配置Nexus
  1.      < mirrors >   
  2. ...  
  3.         < mirror >   
  4.             < id > nexus </ id >   
  5.             < mirrorOf > * </ mirrorOf >   
  6.             < name > Nexus Mirror </ name >   
  7.             < url > http:// < Your  Nexus IP > /nexus/content/groups/public </ url >   
  8.         </ mirror >   
  9. ...  
  10.     </ mirrors >   
  11. ...  
  12.     < profiles >   
  13.         < profile >   
  14.             < id > nexus </ id >   
  15.             < repositories >   
  16.                 < repository >   
  17.                     < id > nexus </ id >   
  18.                     < name > local private nexus </ name >   
  19.                     < url > < Your  Nexus IP > /nexus/content/groups/public </ url >   
  20.                     < releases >   
  21.                         < enabled > true </ enabled >   
  22.                     </ releases >   
  23.                     < snapshots >   
  24.                         < enabled > false </ enabled >   
  25.                     </ snapshots >   
  26.                 </ repository >   
  27.                 < repository >   
  28.                     < id > nexus </ id >   
  29.                     < name > local private nexus </ name >   
  30.                     < url > http:// < Your  Nexus IP > /nexus/content/groups/public-snapshots </ url >   
  31.                     < releases >   
  32.                         < enabled > false </ enabled >   
  33.                     </ releases >   
  34.                     < snapshots >   
  35.                         < enabled > true </ enabled >   
  36.                     </ snapshots >   
  37.                 </ repository >   
  38.   
  39.             </ repositories >   
  40.             < pluginRepositories >   
  41.                 < pluginRepository >   
  42.                     < id > nexus </ id >   
  43.                     < name > local private nexus </ name >   
  44.                     < url > http:// < Your  Nexus IP > /nexus/content/groups/public </ url >   
  45.                     < releases >   
  46.                         < enabled > true </ enabled >   
  47.                     </ releases >   
  48.                     < snapshots >   
  49.                         < enabled > false </ enabled >   
  50.                     </ snapshots >   
  51.                 </ pluginRepository >   
  52.                 < pluginRepository >   
  53.                     < id > nexus </ id >   
  54.                     < name > local private nexus </ name >   
  55.                     < url > http:// < Your  Nexus IP > /nexus/content/groups/public-snapshots </ url >   
  56.                     < releases >   
  57.                         < enabled > false </ enabled >   
  58.                     </ releases >   
  59.                     < snapshots >   
  60.                         < enabled > true </ enabled >   
  61.                     </ snapshots >   
  62.                 </ pluginRepository >   
  63.             </ pluginRepositories >   
  64.         </ profile >   
  65.     </ profiles >   
  66. ...  
  67.     < activeProfiles >   
  68.         < activeProfile > nexus </ activeProfile >   
  69.     </ activeProfiles >   



如果通过Eclipse Maven工具,或者直接操作Maven命令行,将jar部署至nexus:
pom.xml

Xml代码  Maven零散笔记——配置Nexus
  1. < project >     
  2. ...    
  3. < distributionManagement >     
  4.   < repository >     
  5.     < id > nexus-releases </ id >     
  6.       < name > Nexus Release Repository </ name >     
  7.       < url > http:// < Your  Nexus IP > /nexus/content/repositories/releases/ </ url >     
  8.   </ repository >     
  9.   < snapshotRepository >     
  10.     < id > nexus-snapshots </ id >     
  11.     < name > Nexus Snapshot Repository </ name >     
  12.     < url > http:// < Your  Nexus IP > /nexus/content/repositories/snapshots/ </ url >     
  13.   </ snapshotRepository >     
  14. </ distributionManagement >     
  15. ...    
  16. </ project >     



settings.xml

Xml代码  Maven零散笔记——配置Nexus
  1. < settings >     
  2. ...    
  3. < servers >     
  4.   < server >     
  5.     < id > nexus-releases </ id >     
  6.     < username > admin </ username >     
  7.     < password > admin123 </ password >     
  8.   </ server >     
  9.   < server >     
  10.     < id > nexus-snapshots </ id >     
  11.     < username > admin </ username >     
  12.     < password > admin123 </ password >     
  13.   </ server >       
  14. </ servers >     
  15. ...    
  16. </ settings >     


最后,在项目目录中执行mvn deploy

应该够用了!Maven零散笔记——配置Nexus