使用nexus搭建maven私服
在日常開發中我們會經常使用的第三方jar包,而我們對jar包的管理往往是使用maven去做管理,但是有時候我們發現使用到的一些jar在阿裏的中央倉庫是找不到的,而且就算找到,下載速度也不盡人意,所以我們一般在公司都會去搭建自己的私服,去存放我們開發所需要的jar包。下面我就在自己的雲服務器上搭建一個私服。
一、下載 nexus
下載地址:https://help.sonatype.com/repomanager2/download/download-archives---repository-manager-oss
我這裏使用的是 nexus-2.14.9-01
二、安裝 nexus
在自己服務器找到合適的位置,將剛剛下載的包進行解壓。解壓後出現2個文件夾 nexus-2.14.9-01 和 sonatype-work
三、修改端口
nexus 的配置文件在nexus-2.14.9-01/conf 中,我們可以修改 nexus.properties 文件中的 application-port 端口來改變端口,這個端口默認為8081,這裏我就不做修改了。
由於我使用的是阿裏雲服務器,所以,我需要去阿裏雲服務器上配置防火墻端口的出入棧規則。
四、修改啟動腳本
nexus 的啟動腳本在nexus-2.14.9-01/bin 中 nexus ,其中有兩個地方需要註意 NEXUS_HOME=".." 這個是修改安裝目錄,而此處是.. 可以不用修改,自動獲取上級目錄。 RUN_AS_USER=root 這個是啟動的用戶,這裏一定要修改啟動用戶為root
五、啟動 nexus
./nexus start 啟動 nexus .
嘗試瀏覽器訪問 http://ip:port/nexus
至此,我們的nexus就算搭建完成。
六、添加用戶
這裏我們首先需要登錄,而登錄的初始密碼是 admin/admin123
這裏我們可以通過右鍵用戶去為用戶修改密碼。
下面我們來新增一個用戶。這裏我為我的用戶新增三個權限 分別是開發人員權限,所有倉庫的查看權限,所有倉庫的只讀權限。
七、新增 jar 包
我們平時的jar包可以根據類型加入不同的類別中。
下面在第三方地址下加入jar包
查找剛剛加入的jar包
最後附上我的maven私服的setting文件
<?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"> <!--<localRepository>D:/dev/apache-maven-3.0.4/.m2/repository</localRepository>--> <interactiveMode>true</interactiveMode> <offline>false</offline> <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> <pluginGroup>org.jenkins-ci.tools</pluginGroup> </pluginGroups> <!--配置權限,使用默認用戶--> <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> </mirrors> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>false</activeByDefault> <jdk>1.6</jdk> </activation> <repositories> <!-- 私有庫地址--> <repository> <id>nexus</id> <url>http://ip:port/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!--插件庫地址--> <pluginRepository> <id>nexus</id> <url>http://ip:port/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!--激活profile--> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles> </settings>
-------------------- END ---------------------
最後附上作者的微信公眾號地址和博客地址
公眾號:wuyouxin_gzh
Herrt灬淩夜:https://www.cnblogs.com/wuyx/
使用nexus搭建maven私服