分享

maven下nexus的搭建,jar包上傳等注意事項

 干掉熊猫,我就是国宝 2011-09-14

nexus是用來搭建本地jar包服務器到,具體就不多說了。
主要是參考裡下面到帖子。在此感謝作者。

持續集成之路——搭建Maven私服

Maven倉庫管理-Nexus(轉帖後加強版)

nexus的安裝

1.nexus的下載地址

http://nexus./downloads/
我下載的是nexus-oss-webapp-1.8.0-bundle.tar.gz

解壓後得到2個文件:nexus-oss-webapp-1.8.0 和sonatype-work
前者包含了nexus的運行環境和應用程序,後者包含了你自己的配置和數據。

2.啟動nexus

在上面提到,nexus的運行環境在nexus-oss-webapp-1.8.0目錄,下面就進入這個目錄啟動:

Linux代码  收藏代码
  1. # cd nexus-oss-webapp-1.8.0/bin/jsw/linux-x86-32/   



在這個目錄下包含了一個文件夾和三個文件:lib、nexus、platform和wrapper,其中nexus就是啟動命令。

執行

Linxu代码  收藏代码
  1. # ./nexus   


得到nexus到提示命令  如start,stop,status,restart 等。

輸入

Linux代码  收藏代码
  1. # ./nexus start   



終端出現

Linux代码  收藏代码
  1. Starting Nexus OSS...  
  2. tarted Nexus OSS   


說明nexus啟動成功

注意:jsw文件夾下有很多針對不同操作系統到文件夾,選中適合自己操作系統的文件夾。
也可以把start,stop做成腳本放在桌面上,避免不停的cd
附件為start和stop的腳本,請打開腳本修改自己本機上nexus的路徑。

3.打開nexus

在瀏覽器中訪問: http://localhost:8081/nexus

出現


點擊右上角的login in
輸入帳號:admin
輸入密碼:admin123
登錄成功

配置nexus


由於在新搭建的nexus環境中只是一個空的倉庫,所以第一步就是要和遠程的Maven中心倉庫進行同步。





如果在Reindex之後,並沒有同步到遠程的倉庫,可以檢查每個倉庫的設置。下面是Maven Central的設置:





開打maven目錄-> conf -> settings.xml

找到localRepository
上面到註釋信息寫道:Default: ~/.m2/repository
我們可以添加

Java代码  收藏代码
  1. <localRepository>${M3_HOME}/repository</localRepository>   



${M3_HOME}是maven到安裝路徑,新建個repository文件夾用來裝入本地的jar包

順手把以前默認的repository刪除。

Linux代码  收藏代码
  1. #cd ~  
  2. rm -rf .m2   



依次在settings.xml文件裡輸入

Xml代码  收藏代码
  1.  <!-- nexus帳號和密碼-->  
  2.   
  3.    <server>    
  4.      <id>nexus-releases</id>    
  5.      <username>admin</username>    
  6.      <password>admin123</password>    
  7.    </server>    
  8.    <server>    
  9.      <id>nexus-snapshots</id>    
  10.      <username>admin</username>    
  11.      <password>admin123</password>    
  12.    </server>       
  13.  </servers>    
  14.   
  15. ...  
  16.   
  17. <!-- 引用naxus倉庫組-->  
  18.    <profile>  
  19.        <id>dev</id>  
  20.           <repositories>  
  21.              <repository>  
  22.                  <id>nexus</id>  
  23.                  <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  24.                  <releases>  
  25.                     <enabled>true</enabled>  
  26.                  </releases>  
  27.                  <snapshots>  
  28.                     <enabled>true</enabled>  
  29.                  </snapshots>  
  30.               </repository>  
  31.             </repositories>             
  32.             <pluginRepositories>  
  33.                 <pluginRepository>  
  34.                     <id>nexus</id>  
  35.                     <url>http://127.0.0.1:8081/nexus/content/groups/public</url>  
  36.                     <releases>  
  37.                         <enabled>true</enabled>  
  38.                     </releases>  
  39.                     <snapshots>  
  40.                         <enabled>true</enabled>  
  41.                     </snapshots>  
  42.                 </pluginRepository>  
  43.             </pluginRepositories>  
  44.         </profile>  
  45. ..  
  46.   
  47.  <!-- nexus -->  
  48.   <activeProfiles>  
  49.         <activeProfile>dev</activeProfile>  
  50.   
  51.     </activeProfiles>   


注意:根據標籤位置準確輸入

上傳jar到本地倉庫





選中3rd party 點擊Artifact Upload標籤點擊select artifact(s) 按鈕選擇要上傳到jar包然後再add artiffact -> uplaod artiffact 即可。

編輯pom.xml的時候可能找不到在nexus的jar包
<br />

在nexus裡查詢本地上傳的jar包複製xml代碼到pom.xml文件保存即可。

編輯好pom.xml後保存
完畢後在${M3_HOME}/repository 文件裡可看到導入的jar包。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多