下載nexus包,放入Linux中
vim etc/profile 在該文件最下方 加入:
export RUN_AS_USER=root
進入該nexus的包bin目錄 ./nexus start 啟動服務
在地址欄里輸入服務IP地址和8081端口就可以打開用戶界面,例如http://192.168.40.242:8081/nexus
點Sign In登錄管理頁面,用戶名密碼為,admin和admin123
在Repositories頁面里顯示着,默認已經創建了5個倉庫(2個為group),直接可以拿來用,無需再自行創建倉庫。
使用方法
搭建Maven私有倉庫的主要目的,是為了在團隊多人開發時,只要內網的私有倉庫有下載過依賴的jar包,就直接從私有倉庫獲取,不再通過外網的中央倉庫,畢竟外網的下載速度實在是太慢了。
在項目的pom.xml或者settings.xml文件里加入一下配置信息(區別,pom.xml是針對當前項目,settings.xml是全局的針對所有項目)
配置信息中的id,name和url跟上圖中的倉庫對應,type為proxy,說明它只是代理,只能用於下載jar包,不能用於發布項目。
<repositories> <repository> <id>maven-central</id> <name>maven-central</name> <url>http://192.168.204.132:8081/repository/maven-central/</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
如果想把自己的項目發布到私有倉庫中,可以用另外兩個倉庫,release和snapshots,至於這兩個有啥區別,說白了就是,在版本號后面加“-SNAPSHOTS“”就自動發布到snapshots,不加的話就發布到releases
發布到倉庫的命令是mvn clean deploy
<distributionManagement> <repository> <id>maven-releases</id> <name>maven-releases</name> <url>http://192.168.204.132:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>maven-snapshots</name> <url>http://192.168.204.132:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
其他使用細節
如果用的是eclipse,在settings.xml的配置如下
<profile> <id>localMaven</id> <activation> <jdk>localMaven</jdk> </activation> <repositories> <repository> <id>maven-central</id> <name>maven-central</name> <url>http://192.168.204.132:8081/repository/maven-central/</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile>
這時候記得在eclipse里選擇對應的profile
===========================================================================================
登錄系統后點擊左側菜單欄Views/Repositories下的Repositories選擇Central倉庫點擊下邊的Configuration把Download Remote Indexes屬性設為True保存即可。
然后在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地址,如下