ALL is Well!

          敏捷是一條很長(zhǎng)的路,摸索著前進(jìn)著

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            30 隨筆 :: 23 文章 :: 71 評(píng)論 :: 0 Trackbacks

          搭建repository私服的用處有很多。
          除了如何如何管理好jar包外,還有就是當(dāng) maven2 無(wú)法自動(dòng)獲取某個(gè)jar包時(shí),(例如 oracle的jdbc jar包)
          我們需要手動(dòng)下載此jar包,將其上傳至我們得私服,填寫(xiě)groupId,artifactId,version等信息。
          然后再在pom.xml里進(jìn)行依賴配置。

          我搭建私服的工具是artifactory-2.2.3。
          首先到網(wǎng)上下載artifactory-2.2.3,google一下,什么都有了。
          下載好后,將其解壓到任意目錄。
          由于artifactory自帶了Jetty Web服務(wù)器,所以,只要雙擊\bin\artifactory.bat 即可運(yùn)行。(太方便了)
          待服務(wù)器啟動(dòng)好后,用 http://localhost:8081/artifactory/ 開(kāi)發(fā)頁(yè)面。
          默認(rèn)的用戶名密碼是:admin/password.
          畫(huà)面如下:


          輸入用戶名:admin 密碼:password 登錄。

          進(jìn)入畫(huà)面后,點(diǎn)擊Deploy,選擇要上傳的jar包。


          選中jar包后,點(diǎn)擊 Upload,會(huì)彈出 如下圖畫(huà)面:


          這里的GroupId、ArtifactId、Version便是要在pom.xml里添加依賴時(shí)指定的元素。
          同時(shí),可以點(diǎn)擊POM Editor 來(lái)對(duì)它的 pom.xml進(jìn)行編輯。如下代碼:

          <?xml version="1.0" encoding="UTF-8"?>
          <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance">
            
          <modelVersion>4.0.0</modelVersion>
            
          <groupId>poi</groupId>
            
          <artifactId>poi</artifactId>
            
          <version>3.6</version>
            
          <description>Artifactory auto generated POM</description>
          </project>


          這還不算完!!這只是建立了repository私服,但是怎樣告訴maven在compile、package時(shí)去本地私服尋找依賴包呢?

          有兩種方式來(lái)配置,一是在settings.xml里指定,二是在項(xiàng)目的pom.xml中指定。

          我是在settings.xml中進(jìn)行指定,在settings.xml文件中,加入Profile節(jié)點(diǎn)。
          (關(guān)于此節(jié)點(diǎn)的說(shuō)明,請(qǐng)參見(jiàn):http://www.aygfsteel.com/jnbzwm/archive/2010/09/03/330862.html


          <profiles>
              
          <profile>
                
          <id>localrepo</id>
                
          <activation>
                  
          <jdk>1.6</jdk>
                
          </activation>
                
          <repositories>
                  
          <repository>
                    
          <id>central</id>
                    
          <name>artifactory at local</name>
                    
          <url>http://localhost:8081/artifactory/repo</url>
                    
          <layout>default</layout>
                    
          <snapshots>   
                      
          <enabled>false</enabled>   
                   
          </snapshots>
                  
          </repository>
                  
          <repository>   
                   
          <id>snapshots</id>   
                    
          <url>http://localhost:8081/artifactory/repo</url>   
                     
          <releases>   
                      
          <enabled>false</enabled>   
                     
          </releases>   
                  
          </repository>
                
          </repositories>
                
          <pluginRepositories>
                  
          <pluginRepository>
                      
          <id>artifactory</id>
                      
          <name>artifactory plugins at local </name>
                      
          <url>http://localhost:8081/artifactory/plugins-releases</url>
                      
          <snapshots>
                          
          <enabled>false</enabled>
                      
          </snapshots>
                  
          </pluginRepository>
              
          </pluginRepositories>
          </profiles>

          在前一個(gè)學(xué)習(xí)筆記中有提到,配置profile后,需要進(jìn)行激活,所以再在settings.xml中,加入activeProfiles節(jié)點(diǎn)的配置。

            <activeProfiles>
              
          <activeProfile>localrepo</activeProfile>
            
          </activeProfiles>

          這里指定的localrepo 就是我們配置的profile的Id。

          到此,配置結(jié)束。


          本文為原創(chuàng),歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明出處BlogJava
          posted on 2010-09-03 14:15 李 明 閱讀(897) 評(píng)論(0)  編輯  收藏 所屬分類: Maven2
          主站蜘蛛池模板: 仁化县| 青海省| 邢台市| 民勤县| 鸡西市| 平舆县| 鹤山市| 汶川县| 佛山市| 额尔古纳市| 策勒县| 花莲县| 临泽县| 宁陵县| 阿荣旗| 于田县| 杭州市| 石泉县| 日喀则市| 穆棱市| 伊川县| 泰兴市| 华阴市| 吉水县| 宁陵县| 定结县| 阿巴嘎旗| 内乡县| 宜章县| 海南省| 沙坪坝区| 疏勒县| 林芝县| 廉江市| 英山县| 安达市| 托克托县| 阿图什市| 康定县| 东丰县| 开江县|