Nexus安裝及部署(含如何在Tomcat中部署)


1、 Nexus價值
  1)方便-節約帶寬-快
  2)便於統一管理
  3)持續集成需要

2、Nexus下載

  http://www.sonatype.org/nexus/go

3、Nexus啟動

  解壓后進入\nexus-2.14.2-01-bundle\nexus-2.14.2-01\bin\jsw\,根據操作系統類型選擇文件夾,如果是Windows則選擇windows-x**-**文件夾,雙擊console-nexus.bat運行。然后在瀏覽器中輸入
http://127.0.0.1:8081/nexus/即可訪問。可進入nexus-2.14.2-01-bundle\nexus-2.14.2-01\conf\打開nexus.properties文件,修改相關屬性。nexus默認的用戶名和密碼為:admin/admin123。


4、如何通過tomcat部署
  nexus默認是和jetty集成的,如果您使用的是tomcat環境,則按照如下步驟進行配置即可:
  4.1)創建目錄如“F:\tomcatweb\nexus”(用於存放您的nexus),將解壓后的nexus包中的nexus-2.14.2-01 和 sonatype-work兩個文件夾拷貝到nexus目錄中
  4.2)進入\nexus\nexus-2.14.2-01\lib目錄,將非jetty的所有jar文件拷貝到\nexus\nexus-2.14.2-01\nexus\WEB-INF\lib中
  4.3)進入\nexus\nexus-2.14.2-01\nexus\WEB-INF\classes,修改nexus.properties文件:nexus-work=F:/tomcatweb/nexus/sonatype-work/nexus
  4.4)修改tomcat中conf/server.xml文件:

       <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
		<Context docBase="F:\tomcatWeb\nexus\nexus-2.14.2-01\nexus" path="/nexus" reloadable="true"/>
	</Host>

  4.5)啟動tomcat
  使用網址進入:http://localhost:8080/nexus,注意修改用戶名密碼

5、Nexus倉庫
  nexus的倉庫類型分為以下四種:
    group: 倉庫組
    hosted:宿主
    proxy:代理
    virtual:虛擬
  首次登陸nexus后可以看到以下一個倉庫組和多個倉庫:
    Public Repositories: 倉庫組(項目中如果要下載構件的話,配置文件中一般都用倉庫組的URL)
    3rd party: 無法從公共倉庫獲得的第三方發布版本的構件倉庫(如oracle驅動)
    Apache Snapshots: 用了代理ApacheMaven倉庫快照版本的構件倉庫(別忘了更新索引
    Central: 用來代理maven中央倉庫中發布版本構件的倉庫(別忘了更新索引
    Central M1 shadow: 用於提供中央倉庫中M1格式的發布版本的構件鏡像倉庫(一般不用管)
    Releases: 用來部署您公司的發布版本構件的宿主類型倉庫(重要)
    Snapshots:用來部署您公司的快照版本構件的宿主類型倉庫(重要)

  您也可以添加倉庫組或者代理倉庫(如阿里雲maven倉庫),其他的看情況吧。

6、修改本地的maven配置文件
  6.1)進入目錄並打開文件:maven\conf\setting.xml(進入eclipse->windows->Perference->maven->installations中查看您用的是哪個maven)
  6.2)修改:<localRepository>F:\JavaMavenRepo</localRepository>
  6.3)配置倉庫:

<profiles>    
    <profile>    
      <id>companyRep</id>    
      <repositories>    
            <repository>    
                <id>central</id>                                       
                <url>http://localhost:8080/nexus/content/groups/public/</url>         
                <releases>    
                    <enabled>true</enabled>    
                </releases>    
                <snapshots>    
                    <enabled>true</enabled>    
                </snapshots>    
            </repository>    
        </repositories>       
         <pluginRepositories>    
            <pluginRepository>    
              <id>central</id>    
              <url>http://localhost:8080/nexus/content/groups/public/</url>
              <releases>    
                <enabled>true</enabled>    
              </releases>    
              <snapshots>    
                <enabled>false</enabled>    
              </snapshots>    
            </pluginRepository>    
        </pluginRepositories>    
    </profile>    
</profiles> 

6.4)激活profile

<activeProfiles>    
    <activeProfile>companyRep</activeProfile>    
</activeProfiles>  

6.5)配置鏡像

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

  這里配置mirrorOf的值為*,代表maven的所有訪問請求都會指向到Nexus倉庫組。
6.6)添加認證信息

<servers>    
     <server>    
      <id>commanyRep-releases</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>    
    <server>    
      <id>commanyRep-snapshot</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>    
</servers> 

7、自動部署構件到Nexus倉庫
  7.1) 修改pom文件(自動部署)

<distributionManagement>    
       <repository>    
           <id>commanyRep-releases</id>    
           <url>http://localhost:8080/nexus/content/repositories/releases/</url>    
       </repository>    
       <snapshotRepository>    
           <id>commanyRep-snapshot</id>    
           <url>http://localhost:8080/nexus/content/repositories/snapshots/</url>    
       </snapshotRepository>    
  </distributionManagement>

  用戶名密碼可以改為具有部署構件權限的用戶。
  7.2)執行命令:mvn clean deploy

8、手動部署構件到Nexus倉庫
  在nexus的倉庫列表中點擊要部署的目標倉庫,然后點擊Artifact Upload選項卡,選擇文件上傳。


免責聲明!

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



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