Maven總結3/3-----私服、第三方jar包的上傳和下載

nexus私服的安裝和啓動

(1)安裝和啓動

下載nexus的jar包,並下載安裝
在這裏插入圖片描述

在這裏插入圖片描述

從 瀏覽器輸入: http://localhost:8081/nexus

在這裏插入圖片描述

(2)登錄

在這裏插入圖片描述

(3)倉庫類型

倉庫種類
在這裏插入圖片描述

(4)常用組的配置:

在這裏插入圖片描述

nexus上傳和下載jar包

(1)上傳jar包

第一步:配置setting.xml文件

需要在客戶端即部署工程的電腦上配置maven 環境,並修改settings.xml文件,配置連接私服的用戶和密碼 。 此用戶名和密碼用於私服校驗,因爲私服需要知道上傳的賬號和密碼是否和私服中的賬號和密碼一致。
maven包的setting文件如下:

<server>
    <id>releases</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>snapshots</id>
    <username>admin</username>
    <password>admin123</password>
</server>

releases 連接發佈版本項目倉庫;snapshots 連接測試版本項目倉庫

第二步: 配置項目 pom.xml

配置私服倉庫的地址,本公司的自己的 jar 包會上傳到私服的宿主倉庫,根據工程的版本號 決定上傳到哪個宿主倉庫,如果版本爲 release 則上傳到私服的 release 倉庫,如果版本爲 snapshot 則上傳到私服的 snapshot 倉庫。
將下面的代碼複製到要上穿jar包的pom文件中:

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

在這裏插入圖片描述
注意:pom.xml 這裏 和 settings.xml 配置 對應!

測試:查看上傳完成的jar包
在這裏插入圖片描述

(2)下載jar包

在本地安裝的mavne包中Setting.xml文件中,寫入如下配置:

<profile>
    <!--profile 的 id-->
    <id>dev</id>
    <repositories>
        <repository>
            <!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重複-->
            <id>nexus</id>
            <!--倉庫地址,即 nexus 倉庫組的地址-->
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <!--是否下載 releases 構件-->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!--是否下載 snapshots 構件-->
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <!--  插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 -->
        <pluginRepository>
            <!--  插件倉庫的 id 不允許重複,如果重複後邊配置會覆蓋前邊 -->
            <id>public</id>
            <name>Public Repositories</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
        </pluginRepository>
    </pluginRepositories>
</profile>

使用 profile 定義倉庫需要激活纔可生效。

<activeProfiles>
    <activeProfile>dev</activeProfile>
</activeProfiles>

測試:點擊運行,即可在控制檯看到下載的jar包
在這裏插入圖片描述
在這裏插入圖片描述

安裝和下載第三方jar包

(1)安裝第三方jar包到本地倉庫

進入jar包所在目錄運行

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dfile=fastjson-1.1.37.jar -Dpackaging=jar

打開cmd直接運行

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=D:\material\Thirdjar\fastjson-1.1.37.jar

(2)安裝第三方jar包到私服

在settings配置文件中添加登錄私服第三方登錄信息

<server>
    <id>thirdparty</id>
    <username>admin</username>
    <password>admin123</password>
</server>

進入jar包所在目錄運行


mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

打開cmd直接運行

mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=D:\material\Thirdjar\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章