1.解壓nexus文件html
[root@centos6 var]# tar -zvxf nexus-2.12.0-01-bundle.tar.gz
nexus-2.12.0-01: 是nexus的核心文件java
sonatype-work :maven下載jar存放地址centos
2.啓動Nexusmaven
[root@centos6 nexus-2.12.0-01]# ./bin/nexus start - **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
默認狀況下,不建議以root用戶運行Nexus,能夠修改bin/nexus中的配置跳過警告(修改RUN_AS_USER=root)this
[root@centos6 nexus-2.12.0-01]# vi bin/nexus
從新啓動Nexusurl
[root@centos6 nexus-2.12.0-01]# ./bin/nexus start - **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.
注:Nexus默認端口8081,若是想修改端口。修改/conf/nexus.properties文件spa
訪問網址:http://192.168.1.11:8081/nexus/#welcome插件
點擊右上角的 Log In 按鈕便可登錄了。默認登陸帳號/密碼爲: admin/admin123 ,登錄成功後的界面3d
點擊Repositories,將列表中全部Type爲proxy 的項目的 Configuration 中的 Download Remote Indexes 設置爲Trueserver
將Releases倉庫的Deployment Policy設置爲 Allow ReDeploy
填寫完必選字段,點擊Upload Artifact(s)按鈕便可。
3.配置本地項目引用私服
自動發佈構件到遠程倉庫,在工程pom.xml中添加
<distributionManagement> <repository> <id>releases</id><!--這個ID須要與你的release倉庫的Repository ID一致--> <url>http://192.168.1.11:8081/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>snapshots</id><!--這個ID須要與你的snapshots倉庫的Repository ID一致--> <url>http://192.168.1.11:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>
修改本地$MAVEN_HOME\conf目錄下的settings.xml配置文件,添加以下配置
<servers> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers>
在本地工程目錄下執行:
mvn deploy
所部署的包就自動上傳到了nexus安裝目錄下的
4.配置Maven從Nexus下載構件
在POM中配置Nexus私服,這樣的配置只對當前的Maven項目有效。
<!--指定Nexus的構件倉庫--> <repositories> <repository> <id>public</id> <name>Team Maven Repository</name> <url>http://192.168.1.11:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!--指定Nexus的插件倉庫--> <pluginRepositories> <pluginRepository> <id>public</id> <name>Team Maven Repository</name> <url>http://192.168.1.11:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>
在settings.xml中配置profile元素,這樣就能讓本機全部的Maven項目都使用本身的Maven私服。
<properties> <repository> <id>public</id> <name>Team Maven Repository</name> <url>http://192.168.1.11:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <layout>default</layout> <snapshots> <enabled>true</enabled> </snapshots> </repository></properties>