maven私服的配置使用


maven的倉庫分為本地倉庫,遠程倉庫和私服倉庫。
私服倉庫一般是公司內部私有的,內部進行維護的。公司員工連接私服,從私服中下載jar,或者將自身的jar傳到私服上。私服還可以從中央倉庫下載jar,當私服中沒用jar的時候,就會從中央倉庫下載。

搭建私服

下載

下載 Nexus,下載地址:http://www.sonatype.org/nexus/archived/
可以選擇zip和tar,分別對應windows和linux。

安裝

將下載的zip解壓,使用cmd進入bin目錄,執行命令:

nexus.bat install

卸載

執行命令:

nexus.bat uninstall

啟動

1、cmd進入目錄,執行命令

nexus.bat start

2、在服務中找到nexus,右鍵啟動

nexus配置文件詳細

查看 nexus 的配置文件conf/nexus.properties
application-port=8081 # nexus 的訪問端口配置
application-host=0.0.0.0 # nexus 主機監聽配置(不用修改)
nexus-webapp=${bundleBasedir}/nexus # nexus 工程目錄
nexus-webapp-context-path=/nexus # nexus 的 web 訪問路徑
nexus-work=${bundleBasedir}/../sonatype-work/nexus # nexus 倉庫目錄
runtime=${bundleBasedir}/nexus/WEB-INF # nexus 運行程序目錄

訪問私服

http://localhost:8081/nexus/

點擊右上角log in,輸入用戶名和密碼

默認是admin/admin123
登錄完畢

上傳jar包到私服

在maven的setting.xml中配置

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

配置項目的pom文件

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

使用deploy命令即可將jar發布到私服,發布工程中的version,如果以snapshot結尾,則可以發布到快照倉庫,如果以release結尾,則可以發布到releases版本。

從私服下載jar包

在setting中配置私服倉庫

<profile>    
 <!--profile 的 id--> 
   <id>dev</id>    
    <repositories>    
      <repository>   
  <!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重復--> 
        <id>nexus</id>    
  <!--倉庫地址,即 nexus 倉庫組的地址--> 
        <url>http://localhost:8081/nexus/content/groups/public/</url>    
  <!--是否下載 releases 構件--> 
        <releases>    
          <enabled>true</enabled>    
        </releases>    
  <!--是否下載 snapshots 構件--> 
        <snapshots>    
          <enabled>true</enabled>    
        </snapshots>    
      </repository>    
    </repositories>   
  <pluginRepositories>   
     <!-- 插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 --> 
        <pluginRepository>   
         <!-- 插件倉庫的 id 不允許重復,如果重復后邊配置會覆蓋前邊 --> 
            <id>public</id>   
            <name>Public Repositories</name>   
            <url>http://localhost:8081/nexus/content/groups/public/</url>   
        </pluginRepository>   
    </pluginRepositories>   
 </profile>   

激活

  <activeProfiles> 
    <activeProfile>dev</activeProfile> 
  </activeProfiles> 


免責聲明!

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



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