一,下載nexus(linux版本)
下載nexus
(maven管理庫),選擇linux
版本進行下載(,下載好之后也上傳到/usr/local/nexus
目錄下。
地址:http://www.sonatype.org/nexus/go/
使用wget命令下載 wget 想要下載nexus版本的地址
wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz
二,安裝配置nexus
解壓nexus
壓縮包到當前文件夾
nexus-2.11.4-01-bundle.tar.gz
生成了兩個目錄(一個 nexus 服務,一個私有庫目錄)
[root@iZ2ze9ipfjhle3cz3cgb0rZ nexus]# ls
nexus-2.11.4-01 nexus-2.11.4-01-bundle.tar.gz sonatype-work
配置訪問nexus端口
在nexus.properties文件中(該文件位於nexus-2.11.2-03/conf/),默認為8081端口
切換到目錄:/nexus/nexus-2.11.2-03/bin/下,打開文件nexus(vim nexus)
NEXUS_HOME=".."
改為(不修改默認也可以):
NEXUS_HOME="nexus安裝目錄"
RUN_AS_USER=
改為:
RUN_AS_USER=root
切換到/usr/local/nexus/nexus-2.11.2-03/bin/
目錄下,啟動nexus
。
./nexux start
回到瀏覽器,訪問 http://101.201.101.200:8081/nexus/,就進入到了maven管理器。
登錄,默認用戶名 admin
默認密碼 admin123
,到此安裝配置結束。
三,添加jar包到maven管理器
首先添加一個用戶
給用戶添加一些權限
在Respositories
的3rd party
中添加jar
包和填寫依賴信息。
注意:以后添加的第三方jar
包都是上傳到3rd party
這個倉庫的!
注意下面
添加成功!
成功之后,在左上角進行搜索,可以搜到上傳的jar
包信息,把右邊的依賴拷貝到pom.xml
文件中,該jar
包就可以使用了。
這一點不要忘記,把Central
倉庫的Configuration
配置中,Download Remote Indexes
項改為true
。
四,新建maven項目,進行測試
首先在pom.xml
文件中加入指定私服倉庫的地址的配置。
url
標簽的地址/nexus/content/groups/public/
就是這樣子搞的!
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
如果沒有效果,或者下載的沒有jar包,只有兩個.lastUpload文件等情況,可以換成下面的方式試一下,估計就可以了
<repositories>
<repository>
<id>maven-ossez</id>
<name>OSSEZ Repository</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-ossez</id>
<name>OSSEZ Repository</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
然后再添加剛才的jar
包對應的依賴,你會發現已經下載了對應的jar
包並且可以使用了。(settings.xml配置文件還使用阿里雲鏡像即可,不需要更改settings.xml的配置)
<dependency>
<groupId>com.test.fantongxue</groupId>
<artifactId>ftx-test</artifactId>
<version>1.0.0</version>
</dependency>
寫測試方法進行測試,TestUtil
工具類是可以使用的。
public static void main(String[] args) {
TestUtil testUtil=new TestUtil();
Integer add = testUtil.add(1, 2);
System.out.println(add);
}
效果如下圖
五,maven私服倉庫的擴展
下面是對maven
私服倉庫的擴展!
項目使用nexus私服的插件,在項目的pom.xml文件中指定插件倉庫
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
如果想本機所有的maven項目都使用私服的組件,可以在maven的設置文件settings.xml中添加屬性,並激活
<profiles>
<profile>
<id>nexusProfile</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 激活 -->
<activeProfiles>
<activeProfile>nexusProfile</activeProfile>
</activeProfiles>
項目發布到私服,maven項目使用命令:mvn clean deploy;需要在pom文件中配置一下代碼;
<distributionManagement>
<repository>
<id>user-release</id>
<name>User Project Release</name>
<url>http://192.168.1.103:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshots</id>
<name>User Project SNAPSHOTS</name>
<url>http://192.168.1.103:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>