maven私服nexus3.9安裝配置


maven私服nexus3.9安裝配置

私服介紹

私服是指私有服務器,是架設在局域網的一種特殊的遠程倉庫,目的是代理遠程倉庫及部署第三方構建。有了私服之后,當 Maven 需要下載構件時,直接請求私服,私服上存在則下載到本地倉庫;否則,私服請求外部的遠程倉庫,將構件下載到私服,再提供給本地倉庫下載。Nexus是一個強大的Maven倉庫管理器,它極大地簡化了本地內部倉庫的維護和外部倉庫的訪問。

本人的安裝環境:

1、操作系統:Windows 10 /Windows 7

2nexus版本:nexus-3.9.0-01-win64Nexus 專業版是需要付費的,這里我們下載開源免費版 Nexus OSS

下載地址:https://www.sonatype.com/nexus-repository-oss

也可以直接訪問:https://www.sonatype.com/oss-thank-you-win64.zip

進行下載。

下載下來為一個壓縮包:

解壓到自己的安裝目錄:

進入/nexus-3.6.1-02-win64/nexus-3.6.1-02/bin目錄下,以管理員身份打開命令行:nexus /install Nexus3 ,該命令將會將Nexus Repository注冊成為Windows服務。啟動剛剛注冊的Nexus3服務,啟動需要幾分鍾。

打開瀏覽器,輸出localhost:8081,出現如下界面,安裝成功。

使用默認的用戶名和密碼登陸(admin/admin123),

可以點擊上面的"設置"圖標,在"設置"里可以添加用戶、角色等。

 

一些概念:
1.component name
的一些說明: 
  1
maven-centralmaven中央庫,該倉庫代理Maven中央倉庫,默認從https://repo1.maven.org/maven2/拉取jar ,其策略為Release,只會下載和緩存中央倉庫中的發布版本構件。
  2
maven-releases:私庫發行版jar 
  3
maven-snapshots:私庫快照(調試版本)jar 
  4
maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml中使用。

 

2.Nexus默認的倉庫類型有以下四種:
  1
group(倉庫組類型):又叫組倉庫,開發人員自己設定的倉庫組;

2hosted(宿主類型):內部項目的發布倉庫(內部開發人員,發布上去存放的倉庫);

 3proxy(代理類型):從遠程中央倉庫中尋找數據的倉庫

 4virtual(虛擬類型):虛擬倉庫(這個基本用不到,重點關注上面三個倉庫的使用)

 

3.Policy(策略):表示該倉庫為發布(Release)版本倉庫還是快照(Snapshot)版本倉庫,snapshots是快照版本,也就是不穩定版本。

 

4.Nexus倉庫分類的概念:

1Maven可直接從宿主倉庫下載構件,也可以從代理倉庫下載構件,而代理倉庫間接的從遠程倉庫下載並緩存構件

2)為了方便Maven可以從倉庫組下載構件,倉庫組並沒有實際的內容(下圖中用虛線表示),訪問它時,它會轉向包含的宿主倉庫或者代理倉庫獲得實際構件的內容).


Nexus自帶Jetty容器,默認的端口是8081若想修改Nexus的服務端口,可以在nexus-3.9.0-01-win64\sonatype-work\nexus3\etc\ nexus.properties配置中修改 application-port=自己設置的端口號。

5.Nexus的工作目錄是sonatype-work(路徑一般在nexus同級目錄下),用戶數據和設置都在這個目錄下面,若要備份,備份這個目錄即可;

 

Nexus的web界面功能介紹

1.1  Search


這個就是類似Maven倉庫上的搜索功能,就是從私服上查找是否有哪些包。

Search這級是支持模糊搜索的,如圖所示:

如果進入具體的目錄,好像不支持模糊搜索,如圖所示:

1.2  Browse

這里查看所有的庫以及庫里面的組件

 

1.3 Blob Stores
文件存儲的地方,創建一個目錄的話,對應文件系統的一個目錄,如圖所示:

2.1 Repositories

Proxy就是代理的意思,代理中央Maven倉庫,當PC訪問中央庫的時候,先通過Proxy下載到Nexus倉庫,然后再從Nexus倉庫下載到PC本地。
這樣的優勢只要其中一個人從中央庫下來了,以后大家都是從Nexus私服上進行下來,私服一般部署在內網,這樣大大節約的寬帶。
創建Proxy的具體步驟

1--點擊"Create Repositories"按鈕

2--選擇要創建的類型

3--填寫詳細信息
Name
:就是為代理起個名字
Remote Storage:
代理的地址,Maven的地址為: https://repo1.maven.org/maven2/
Blob Store:
選擇代理下載包的存放路徑

創建完成后如下圖:

將添加的代理倉庫加入 Public Repositories 倉庫組

4.配置遠程索引

新搭建的neuxs環境只是一個空的倉庫,需要手動和遠程中心庫進行同步,nexus默認是關閉遠程索引下載。

由於使用代理之前需要先下索引,但是索引較大400M,從國外可能線上更新索引會比較慢,我們可以使用迅雷之類的加速工具,離線下載然后再上傳到nexus服務器即可。 
索引下載地址:http://repo.maven.apache.org/maven2/.index/

nexus-maven-repository-index.gz nexus-maven-repository-index.properties indexer-cli-6.0.0.jar 放置到同一目錄下,運行命令:java -jar indexer-cli-6.0.0.jar -u nexus-maven-repository-index.gz -d indexer

indexer中的全部文件移動到 sonatype-work\nexus3\blobs\倉庫名下,

\ sonatype-work\nexus3\blobs\倉庫名下面新建index nexus-maven-repository-index.gz nexus-maven-repository-index.properties 放到index文件夾下

重新啟動nexus。等待一段時間

Status Online-Remote Avaliable 變為Online-Remote Avaliable

使用一些Maven代理鏡像網站就不用手動下索引了

<mirrors>

    <mirror>

        <id>alimaven</id>

        <name>aliyun maven</name>

        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

    <mirror>

        <id>central</id>

        <name>Maven Repository Switchboard</name>

        <url>http://repo1.maven.org/maven2/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

    <mirror>

        <id>repo2</id>

        <mirrorOf>central</mirrorOf>

        <name>Human Readable Name for this Mirror.</name>

        <url>http://repo2.maven.org/maven2/</url>

    </mirror>

    <mirror>

        <id>ibiblio</id>

        <mirrorOf>central</mirrorOf>

        <name>Human Readable Name for this Mirror.</name>

        <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>

    </mirror>

    <mirror>

        <id>jboss-public-repository-group</id>

        <mirrorOf>central</mirrorOf>

        <name>JBoss Public Repository Group</name>

        <url>http://repository.jboss.org/nexus/content/groups/public</url>

    </mirror>

    <!-- 中央倉庫在中國的鏡像 -->

    <mirror>

        <id>maven.net.cn</id>

        <name>oneof the central mirrors in china</name>

        <url>http://maven.net.cn/content/groups/public/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

    <mirror>

        <id>alimaven</id>

        <mirrorOf>central</mirrorOf>

        <name>aliyun maven</name>

        <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>

    </mirror>

</mirrors>

Maven集成

集成的方式主要分以下種情況:代理中央倉庫、Snapshot包的管理、Release包的管理、第三方Jar上傳到Nexus上。找到myeclipse使用的maven配置文件\apache-maven-3.3.9\conf\settings.xml,如果myeclispe沒修改,默認起作用的是C盤下

C:\Users\${user.name}\.m2\settings.xml 。

 

<servers>

    <server>

        <id>nexus</id>

        <username>admin</username>

        <password>admin123</password>

    </server>

</servers>

<mirrors>

    <mirror>

        <!--This sends everything else to /public -->

        <id>nexus</id>

        <!--此處配置所有的構建均從私有倉庫中下載 *代表所有 -->

        <mirrorOf>*</mirrorOf>

        <!--私服路徑 -->

        <url>http://localhost:8081/repository/maven-public/</url>

    </mirror>

</mirrors>

 

<profiles>

    <profile>

        <id>nexus</id>

        <!--Enable snapshots for the built in central repo to direct -->

        <!--all requests to nexus via the mirror -->

        <repositories>

            <repository>

                <id>central</id>

                <url>http://central</url>

                <releases>

                    <enabled>true</enabled>

                </releases>

                <snapshots>

                    <enabled>true</enabled>

                </snapshots>

            </repository>

        </repositories>

        <pluginRepositories>

            <pluginRepository>

                <id>central</id>

                <url>http://central</url>

                <releases>

                    <enabled>true</enabled>

                </releases>

                <snapshots>

                    <enabled>true</enabled>

                </snapshots>

            </pluginRepository>

        </pluginRepositories>

    </profile>

</profiles>

 

<activeProfiles>

    <!--make the profile active all the time -->

    <activeProfile>nexus</activeProfile>

</activeProfiles>

 

</settings>

注意以下三點:

1 <mirror><url>標簽內的地址修改成nexus服務的地址。
2 <servers>
標簽內填寫nexus服務的賬號密碼,發布maven項目到nexus時,需要用到。
3 <server><id>
id需要跟<mirror><id>一致。

如果想發布項目到nexus倉庫

還需要在項目的pom.xml文件內,指定發布地址:

    <distributionManagement>

        <repository>

            <id>nexus</id>

            <name>Releases</name>

            <!-- repository/maven-releases管理頁面復制url地址 -->

            <url>http://localhost:8081/repository/maven-releases/</url>

        </repository>

        <snapshotRepository>

            <id>nexus</id>

            <name>Snapshot</name>

            <url>http://localhost:8081/repository/maven-snapshots/</url>

        </snapshotRepository>

    </distributionManagement>

關於倉庫詳細配置可參考官方文檔:

http://books.sonatype.com/nexus-book/reference3/admin.html#admin-repositories

 

Nexus3.x.x上傳第三方jar

第一種方式:寫腳本上傳jar

mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=D:\ojdbc6-11.2.0.3.jar -Durl=http://localhost:8081/repository/maven-releases/ -DrepositoryId=nexus

 

其中-DgroupId 為上傳的jargroupId

-DartifactId 為上傳的jarartifactId

-Dversion 為上傳的jar的需要被依賴的時候的版本號

然后是-Dpackagingjar-Dfilejar包路徑

-Durl 為要上傳的路徑

-DrepositoryId repository的唯一標示,跟第二步中賦權配置的server相同

第二種方式:使用Nexus Repository Manager圖形化界面上傳

 

參考博文:

http://www.blogjava.net/xiaomage234/archive/2014/05/13/413584.html

https://www.cnblogs.com/kevingrace/p/6201984.html

http://blog.csdn.net/lusyoe/article/details/52821088

https://www.zhihu.com/question/47261839/answer/134716331

http://blog.csdn.net/iopfan/article/details/71107686


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM