Maven中的依賴是從服務器倉庫中下載的,Maven的倉庫只有兩大類:java
Maven用戶直接鏈接遠程倉庫下載構件的作法是Maven不建議使用的(尤爲是對一個開發團隊來講),Maven的最佳實踐就是使用Maven私服來構建整個團隊的項目部署和管理。私服是一種特殊的遠程倉庫,它是架設在局域網內的倉庫服務,私服代理廣域網上的遠程倉庫,供局域網內的Maven用戶使用。當Maven須要下載構件的時候,它從私服請求,若是私服上不存在該構件,則從外部的遠程倉庫下載,緩存在私服上以後,再爲Maven的下載請求提供服務。web
構建Maven私服使用Nexus,Nexus是一個強大的Maven倉庫管理器,它極大地簡化了本身內部倉庫的維護和外部倉庫的訪問。利用Nexus你能夠只在一個地方就可以徹底控制訪問 和部署在你所維護倉庫中的每一個Artifact。Nexus是一套「開箱即用」的系統不須要數據庫,它使用文件系統加Lucene來組織數據。Nexus 使用ExtJS來開發界面,利用Restlet來提供完整的REST APIs,經過m2eclipse與Eclipse集成使用。Nexus支持WebDAV與LDAP安全身份認證。spring
說完了私服的好處,你是否是已經等不及開始構建你的maven私服了,那麼咱們開始一塊兒構建咱們的私服。首先進入Nexus的網站http://www.sonatype.org/nexus/go/,找到你須要的包,下載(演示在CentOS上安裝):docker
若是你但願用一些歷史版本的包,https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3,裏面自行查找。首先下載對應的包到服務器上:數據庫
mkdir tools #新建tools目錄
cd tools # 進入tools目錄
wget http://download.sonatype.com/nexus/3/nexus-3.14.0-04-unix.tar.gz # 下載對應的安裝包
tar zxvf nexus-3.14.0-04-unix.tar.gz # 解壓縮
mv nexus-3.14.0-04/ /usr/local/nexus
cd /usr/local/nexus/bin複製代碼
安裝java運行環境:apache
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel複製代碼
修改nexus.rc,讓root能夠啓動nexus,nexus.rc在/usr/local/nexus/bin/下:vim
vim nexus.rc,刪除run_as_user前面的註釋,後面加上root:run_as_user=root複製代碼
而後按esc按鍵,輸入:wq回車。而後啓動nexus緩存
./nexus run &複製代碼
出現以下內容,表示啓動成功安全
經過http://localhost:8081就能夠訪問了。服務器
首先:前往maven中央倉庫下載 indexer-cli-5.1.1.jar解壓工具
其次下載:nexus-maven-repository-index.properties和nexus-maven-repository-index.gz
再次,將上面下載的3個文件放到同一個路徑下,經過以下命令解壓:
java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer複製代碼
最後,拷貝索引
nexus3.x拷貝到/sonatype-work/nexus3/blobs/default,3.x
複製代碼
首先訪問對應的地址,而後輸入默認用戶名 admin、密碼 admin123:
點擊左側的browse,能夠看到各類repository的type,那麼這些類型有什麼區別呢:
進入設置頁面
做以下操做:
在maven的setting.xml文件中配置私服配置,這種方式配置後全部本地使用該配置的maven項目的pom文件都無需配置私服下載相關配置(下文中192.179.101.1:8081須要替爲你本身的)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
複製代碼
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>複製代碼
<mirrors>複製代碼
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
</mirror>複製代碼
</mirrors>複製代碼
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>複製代碼
<activeProfiles>
<activeProfile>nexus</activeProfile>
<!--<activeProfile>dev</activeProfile>-->
</activeProfiles>複製代碼
</settings>複製代碼
docker確實是個好東西,快速,方便,使用docker部署Nexus那就是幾分鐘的事情具體以下命令:
docker pull sonatype/nexus3
docker run -d -p 8081:8081 --name nexus sonatype/nexus3複製代碼
啓動完成後,方位http://localhost:8081就能夠進入web頁面了,其餘操做和配置和上面的內容一致,所以這部分就不在這裏描述了。關注我,關注測試FROM:https://blog.csdn.net/crisschan