一、爲何須要maven私有倉庫?java
從Maven中央倉庫下載所需的jar包,須要外網的支持。若是公司不能上外網的話則不能從中央倉庫下載所需jar包,公司網速慢的時候也會影響項目構建的速度。用戶能夠用nexus建立私有的maven倉庫。
二、下載和部署Nexusgit
首先下載nexus,下載地址是http://www.sonatype.org/nexus/go 在此頁面能夠下載最新版本的Nexus,能夠下載zip包也能夠下載war包。須要注意的是兩種包的部署方式不同。
zip包部署方式github
a.把zip包解壓到指定路徑如「D:\workbase」 b.運行cmd而後進入「D:\workbase\nexus-2.6.0-05\bin」路徑 c.而後運行nexus.bat install命令安裝nexus d.而後運行nexus.bat start命令啓動nexus
其餘命令有nexus.bat stop中止 nexus.bat restart重啓 nexus.bat uninstall卸載web
war包部署方式apache
直接把war包放到tomcat的webapp下,啓動tomcat便可。bootstrap
在瀏覽器地址欄輸入http://localhost:8088/nexus/即進入nexus首頁。有管理nexus要以管理員身份登陸,點擊首頁右上角的login輸入默認登陸名、密碼admin/admin123便可登陸。瀏覽器
注意與jdk的版本搭配tomcat
官方下載的最新版本是2.6.0-05,jdk1.6版本啓動nexus有錯誤不能啓動,錯誤以下:服務器
Launching a JVM...
jvm 5 | java.lang.UnsupportedClassVersionError: org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor version 51.0app
在官網下載早期版本的Nexus如2.4.0替換掉便可。
登陸系統後點擊左側菜單欄Views/Repositories下的Repositories選擇Central倉庫點擊下邊的Configuration把Download Remote Indexes屬性設爲True保存便可。
點擊Repositories ,能夠看到倉庫列表,包括下面幾種:
Public Repositories 倉庫組
3rd part 三方庫,能夠上傳jar包到這個倉庫
Central maven中心倉庫
Releases 本身項目中發佈的構建
Snapshots trunk 下開發一個項目
而後在Central倉庫上右鍵而後點擊Repair Index 便可下載中心倉庫的索引文件,稍等幾分鐘點擊下邊的Browse Index便可看見下載的索引文件。
往Public Repositories中添加Central倉庫,點擊Public Repositories在Configuration選項卡中把Central移到左側便可。
最後在本身的應用中把中心倉庫配置成創建的私有倉庫地址便可,修改本地的maven配置文件,C:\Documents and Settings\用戶名\.m2\setting.xml
在mirrors添加mirror節點地址指向創建的私有倉庫地址,mirrorOf屬性值設爲central爲了覆蓋超級pom中指定的central地址,以下
Maven 倉庫
Maven 包集中存放的地方,就是 Maven 倉庫。這些倉庫,能夠是放在本地,也能夠放在某個遠程服務器上。 能夠是私有倉庫,也能夠是公開的。
maven { url 'file:///Users/my-user-name/Documents/Android/repo/' }
maven { url 'http://192.168.99.100:8081/content/repositories/releases/' }
maven { url 'https://raw.githubusercontent.com/liaohuqiu/umeng-libs/master/repository' }
附錄: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/