使用Nexus搭建Maven私有倉庫

背景:使用Maven構建項目的時候,如果很多jar包需要下載,如果都從遠程中央倉庫下載,則下載速度比較慢,而且如果多人同時進行開發的時候,相同的jar包則需要多次佔用外網帶寬資源進行下載。因此,有必要再內網搭建一個私服倉庫,所有人員先從私服進行下載,如果私服上沒有則私服從外網下載以後再進行分發。下面是搭建步驟:

nexus搭建maven私服,nexus搭建maven


下載nexus

首先,從以下地址下載nexus:

http://www.sonatype.com/download-oss-sonatype

選擇下載nexus-2.13.0-01-bundle.tar.gz,適用於所有平臺,本文將在linux系統下安裝,操作系統信息如下:

Linux version 3.10.0-123.el7.x86_64 ([email protected]) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Mon May 5 11:16:57 EDT 2014

注意nexus是基於Java開發的,這裏之所以沒去下載nexus-3.0.0-03-unix.tar.gz是因爲它要求安裝JDK8及以上,由於我的linux操作系統安裝的jdk是7,所以選擇nexus-2.13.0-01-bundle.tar.gz,否則出現如下錯誤:

No suitable Java Virtual Machine could be found on your system.
The version of the JVM must be at least 1.8 and at most 1.8.
Please define INSTALL4J_JAVA_HOME to point to a suitable JVM.

啓動nexus服務

將安裝包拷貝到linux操作系統路徑下,解壓,然後cd到bin目錄,可輸入以下nexus命令:

Usage: ./nexus { console | start | stop | restart | status | dump }
./nexus start

注意,如果你是root賬戶,會出現如下錯誤:

****************************************
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用戶。解決方法很簡單,換個其它用戶即可;

或者設置環境變量export RUN_AS_USER=root,環境變量路徑vi /etc/profile,在最下方添加如下代碼:

export RUN_AS_USER=root

如果要改變端口的話,可以重新編輯conf/nexu.properties中的application-port=8888

啓動nexus後,打印如下信息:

[root@localhost bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.

這裏提個醒,一定要注意java的版本,以及8081端口是否被佔用等

一切順利的話,我們在瀏覽器輸入http://192.168.0.108:8888/nexus/(這裏192.168.0.108是nexus安裝的服務器ip),即可訪問nexus客戶端,默認的用戶名和密碼:admin admin123

如下圖:


 

上傳jar包到nexus

首先是下載jar包,oracle的驅動包,由於Oracle授權問題,maven中央倉庫沒提供,我們自己下載,

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

然後按如下圖進行操作:

在Artifact Upload頁面,進行如下操作,具體就不細說了,見圖:

弄完之後,我們可以在如下頁面看到自己上傳的jar包;

POM.XML配置

拷貝上圖右下角的XML信息到pom.xml,即

<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc6</artifactId>
  <version>11.2.0.4.0</version>
</dependency>

另外配置下倉庫信息(在pom.xml中配置就可以),如下

    <repositories>  
        <repository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://192.168.0.108:8888/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </repository>  
    </repositories>   
    <pluginRepositories>  
        <pluginRepository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://192.168.0.108:8888/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </pluginRepository>  
    </pluginRepositories> 

想驗證是否成功的話,可以查看maven日誌,會發現從你的私服下載jar包

後續

關於nexus,還有很多其它功能沒去嘗試,這裏只是簡單的使用一下,後續有空可以深入研究。



參考文章:http://www.bkjia.com/Javabc/1147547.html(內容略有補充)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章