Nexus私服搭建與maven集成


 

公司之前的代碼沒有使用maven管理jar包,現在要求使用maven,在整理依賴的過程中發現某些jar包maven上並不更新了,還有些jar包maven上根本沒有,比如釘釘的jar包。

所以沒辦法只能自己搭建私服,因為是在整理中,所以就在自己的windows電腦上搭建的。

Nexus的官網 https://www.sonatype.com/download-oss-sonatype  我下載的是nexus-2.14.10-01-bundle版本的。

下載解壓

進入nexus-2.14.10-01-bundle\nexus-2.14.10-01\bin目錄,打開該目錄的命令行窗口,執行nexus install 命令,安裝nexus,安裝完成后進入服務配置界面,啟動nexus服務

windows+R 輸入下面命令進入服務配置界面

服務啟動成功后打開瀏覽器輸入http://localhost:8081/nexus nexus默認端口是8081

點擊右上角的log in 登錄,默認賬號: admin  默認密碼 :admin123

 

登錄成功后點擊左邊的Views/Repositories下的Repositories 打開Repositories窗口可以看到默認創建的一些倉庫,我這里使用到了Public Repositories 和 3rd party  Public Repositories是公共的倉庫,maven倉庫下載的會放在這里,3rd party是第三方倉庫,我們可以自己添加網上下載下來的第三方的jar包,或者是之前自己的jar包

這樣Nexus的私服就搭建完成了,后面我們還需要配置一下maven的setting.xml文件,來使用nexus私服

打開maven的setting文件

<servers>下配置,設置如果需要連接到遠程服務器使用的用戶名和密碼

<server>   
    <id>nexus-releases</id>   
    <username>admin</username>   
    <password>admin123</password>   
</server>
<server>   
    <id>nexus-snapshots</id>   
    <username>admin</username>   
    <password>admin123</password>   
</server>

<mirrors>下配置,設置maven倉庫的鏡像為我們剛剛安裝好的nexus私服

<mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>

<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>

再添加下面配置激活倉庫

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

到此配置完成,重啟服務后將我們的maven項目更新后,再進入私服頁面會發現下載了我們項目中使用的jar包

但是這樣我們之前的jar包仍然沒有加入到私服中,我們需要手動添加jar包到私服中

打開我們的3rd party倉庫,選擇artifact upload來添加jar包

上傳成功后就可以在Browse Index中刷新看到我們剛剛添加的jar包,右側就是maven中pom.xml的配置,直接復制過去就好,這樣我們就完成了上傳jar包到私服,配置到項目中

之后我們可以將maven本地倉庫 .m2中的錯誤的jar包刪除重新構建項目,這樣項目的依賴應該就完成了,不會有找不到jar包的錯誤了。

如果沒有用到maven上找不到的jar包,只是某些jar包下載慢或者下載失敗的話,可以嘗試使用國內的鏡像,比如阿里的鏡像等,如果還是失敗可以使用私服。

吐槽下釘釘上下載的jar包名字 taobao-sdk-java-auto_1479188381469-20180919 能不能規范點。。。

目前只是將項目的依賴整理完了,目前項目還是使用ant的打包方式,后續應該會使用maven打包或者maven使用ant打包插件的方式打包


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM