Maven倉庫匯總


來源:http://tianya23.blog.51cto.com/1081650/386908

1、maven 倉庫地址:

共有的倉庫
http://repo1.maven.org/maven2/
http://repository.jboss.com/maven2/
http://repository.sonatype.org/content/groups/public/
http://mirrors.ibiblio.org/pub/mirrors/maven2/org/acegisecurity/

私有的倉庫
http://repository.codehaus.org/
http://snapshots.repository.codehaus.org/
http://people.apache.org/repo/m2-snapshot-repository
http://people.apache.org/repo/m2-incubating-repository/

 
同時可以搭建自己的maven倉庫:私服, 搭建的方式參考如下:

2、收集的外部倉庫地址

 
附:Maven倉庫的搭建
 訪問 http://nexus.sonatype.org/downloads/下載Nexus。 
   啟動Nexus,就是啟動一個web服務器,它的默認地址是localhost:8081。Nexus在一個名為Jetty的servlet容器中運行,它使用一個名為Tanuki Java Service Wrapper的本地服務包裹器啟動。這個服務包裹器可以被配置成以Windows服務或Unix守護線程的形式運行Nexus。要啟動Nexus,你需要為你的平台找到合適的啟動腳本。要查看可用平台的列表,查看${NEXUS_HOME}/bin/jsw目錄的內容。
   可執行文件在%nexus安裝目錄%\nexus-webapp-1.0.0\binjsw\windows-x86-32下: 
   InstallNexus.bat/UninstallNexus.bat是安裝/卸載nexus為windows service。 
   Nexus.bat是直接在命令行中啟動Nexus,如果不想安裝Nexus為windows service,可以用這個文件來手工控制Nexus的啟動退出。 
1.配置nexus 
   首先登錄,默認地址 http://localhost:8081/nexus/,默認用戶名密碼為admin/admin123. 
    nexus默認是關閉遠程索引下載功能的。開啟的方式: 
    點擊Administration菜單下面的Repositories,將這三個倉庫Apache Snapshots,Codehaus Snapshots,Maven Central的 
    Download Remote Indexes修改為true。然后在這三個倉庫上分別右鍵,選擇Re-index,這樣Nexus就會去下載遠程的索引文件。 
2.管理倉庫 
以管理員用戶登陸然后點擊左邊導航菜單Administration下面的Repositories。Nexus提供了三種不同的倉庫。 
(1)代理倉庫 
一個代理倉庫是對遠程倉庫的一個代理。默認情況下,Nexus自帶了如下配置的代理倉庫: 
Apache Snapshots 
這個倉庫包含了來自於Apache軟件基金會的快照版本。 http://people.apache.org/repo/m2-snapshot-repository 
Codehaus Snapshots 
這個倉庫包含了來自於Codehaus的快照版本。  http://snapshots.repository.codehaus.org/ 
Central Maven Repository 
這是中央Maven倉庫(發布版本)。  http://repo1.maven.org/maven2/ 
(2)宿主倉庫 
一個宿主倉庫是由Nexus托管的倉庫。Maven自帶了如下配置的宿主倉庫。 
3rd Party 
這個宿主倉庫應該用來存儲在公共Maven倉庫中找不到的第三方依賴。這種依賴的樣例有:你組織使用的,商業的,私有的類庫如Oracle JDBC驅動。 
Releases 
這個宿主倉庫是你組織公布內部發布版本的地方。 
Snapshots 
這個宿主倉庫是你組織發布內部快照版本的地方。 
(3)虛擬倉庫 
一個虛擬倉庫作為Maven 1的適配器存在。Nexus自帶了一個central-m1虛擬倉庫 
3. 管理組 
組是Nexus一個強大的特性,它允許你在一個單獨的URL中組合多個倉庫。Nexus自帶了兩個組:public和public-snapshots。public組中組合了三個宿主倉庫:3rd Party, Releases, 和Snapshots,還有中央Maven倉庫。而public-snapshots組中組合了Apache Snapshots和Codehaus Snapshots倉庫。 
4. 配置maven 
要讓maven使用Nexus作為倉庫,要修改~/.m2/settings.xml. 
Xml代碼 
<profiles> 
   <profile> 
     <id>nexus</id> 
     <repositories> 
       <repository> 
           <id>nexus</id> 
           <name>local private nexus</name> 
           <url>http://localhost:8081/nexus/content/groups/public</url> 
       </repository> 
     </repositories> 
   </profile> 
   <profile> 
     <id>nexus-snapshots</id> 
     <repositories> 
       <repository> 
           <id>nexus-snapshots</id> 
           <name>local private nexus snapshots</name> 
           <url>http://localhost:8081/nexus/content/groups/public-snapshots</url> 
       </repository> 
     </repositories> 
   </profile> 
</profiles>
<activeProfiles> 
    <activeProfile>nexus</activeProfile> 
    <activeProfile>nexus-snapshots</activeProfile> 
</activeProfiles>
5.部署構件至Nexus 
   要部署構件至Nexus,在distributionManagement中提供倉庫URL,然后運行mvn deploy。Maven會通過一個簡單的HTTP PUT將項目POM和構件推入至你的Nexus安裝。需要配置你項目POM中distributionManagement部分的repository。 
Xml代碼 
<distributionManagement> 
<repository> 
    <id>releases</id> 
    <name>Internal Releases</name> 
    <url>http://localhost:8081/nexus/content/repositories/releases</url> 
</repository> 
<snapshotRepository> 
    <id>Snapshots</id> 
    <name>Internal Snapshots</name> 
    <url>http://localhost:8081/nexus/content/repositories/snapshots</url> 
</snapshotRepository> 
</distributionManagement>
這樣還沒完,這時如果部署會報錯,還要在~/.m2/settings.xml中添加如下的服務器登錄信息: 
Xml代碼 
<server> 
<id>releases</id> 
<username>admin</username> 
<password>admin123</password> 
</server> 
<server> 
<id>Snapshots</id> 
<username>admin</username> 
<password>admin123</password> 
</server>
部署第三方構件: 
構件可能是私有數據庫的JDBC驅動如Oracle,或者你依賴於另一個JAR,它既不開源也無法免費獲得。在這樣的情況下,你就需要手動拿來這些構件然后發布到你自己的倉庫中。Nexus提供宿主的"third-party"倉庫,就是為了這個目的。 
使用以下命令發布該文件至Nexus: 
Java代碼 
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14 
-Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar   
-Durl=http://localhost:8081/nexus/content/repositories/thirdparty   
-DrepositoryId=thirdparty
6.Nexus監聽端口 
默認情況下,Nexus監聽端口8081。你可以更改這個端口,通過更改${NEXUS_HOME}/conf/plexus.properties的值,為此,停止Nexus,更改文件中applicationPort的值,然后重啟Nexus。 
7.Maven Profiles 
   Maven中的profile是一組可選的配置,可以用來設置或者覆蓋配置默認值。有了profile,你就可以為不同的環境定制構建。profile可以在pom.xml中配置,並給定一個id。然后你就可以在運行Maven的時候使用的命令行標記告訴Maven運行特定profile中的目標。以下pom.xml使用production profile覆蓋了默認的Compiler插件設置。 
Xml代碼 
<profiles> 
   <profile> 
     <id>production</id> 
     <build> 
       <plugins> 
         <plugin> 
           <groupId>org.apache.maven.plugins</groupId> 
           <artifactId>maven-compiler-plugin</artifactId> 
           <configuration> 
             <debug>false</debug> 
             <optimize>true</optimize> 
           </configuration> 
         </plugin> 
       </plugins> 
     </build> 
   </profile> 
</profiles> 
要使用production profile來運行mvn install,你需要在命令行傳入-Pproduction參數。要驗證production profile覆蓋了默認的Compiler插件配置,可以像這樣以開啟調試輸出(-X) 的方式運行Maven。 
    如果你開始大量使用Maven profile,你會希望將profile從POM中分離,使用一個單獨的文件如profiles.xml。你可以混合使用定義在pom.xml中和外部profiles.xml文件中的profile。只需要將profiles元素放到${basedir}目錄下的profiles.xml文件中,然后照常運行Maven就可以。profiles.xml文件的大概內容如下: 
Xml代碼 
<profiles> 
    <profile> 
      <id>development</id> 
      <build> 
        <plugins> 
          <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-compiler-plugin</artifactId> 
            <configuration> 
              <debug>true</debug> 
              <optimize>false</optimize> 
            </configuration> 
          </plugin> 
        </plugins> 
      </build> 
    </profile> 
    <profile> 
      <id>production</id> 
      <build> 
        <plugins> 
          <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-compiler-plugin</artifactId> 
            <configuration> 
              <debug>false</debug> 
              <optimize>true</optimize> 
            </configuration> 
          </plugin> 
        </plugins> 
      </build> 
    </profile> 
</profiles>
   settings profile可以應用到所有你使用Maven構建的項目。你可以在兩個地方定義settings profile:定義在~/.m2/settings.xml中的用戶特定settings profile,或者定義在${M2_HOME}/conf/settings.xml中的全局settings profile。


免責聲明!

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



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