記一次 Centos7 Nexus 配置私服(Maven私服)

第一部分   環境搭建

詳見:https://blog.csdn.net/llwy1428/article/details/99537867

第二部分   Nexus 配置

一、倉庫的創建及發佈私有 Jar 包到本地倉庫

1、創建倉庫

2、創建宿主倉庫

說明:

group:倉庫組,項目直接引用的倉庫;

hosted:項目自己創建的倉庫,自己上傳jar包,默認有開發庫(開發階段用)和線上倉庫(項目上線時用);

proxy:遠程引用倉庫。

3、創建 release 倉庫,倉庫名稱 hunter-release (名字自定義), type選擇 : release

4、創建 snapshot 倉庫,倉庫名稱 hunter-snapshot (名字自定義), type選擇 : snapshot

5、創建結果

說明:

maven-central:maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar

maven-releases:私庫發行版jar (上線時用)

maven-snapshots:私庫快照(調試版本,開發時用)jar

maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml中使用。

6、配置本地 Maven 的 settings.xml 配置文件添加如下信息:

代碼如下

<server>
    <id>hunter-realease</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>hunter-snapshot</id>
    <username>admin</username>
    <password>admin123</password>
</server>

7、基本配置

(1)IDEA 中配置 JDK1.8 (略);

(2)IDEA 中配置 Maven (略);

(3)打開 IDEA  創建項目(項目創建過程:略)。

8、配置項目的 pom.xml 文件

    <distributionManagement>
        <repository>
            <id>hunter-release</id>
            <name>Release Repository of Hunter</name>
            <url>http://192.168.11.16:8081/repository/hunter-release/</url>
        </repository>
        <snapshotRepository>
            <id>hunter-snapshot</id>
            <name>Snapshot Repository of Hunter</name>
            <url>http://192.168.11.16:8081/repository/hunter-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

注意:<distributionManagement></distributionManagement> 中的 id 要和 Maven settings.xml 中 server 中配置的 id 要一一對應。

8、編寫測試工具類,打包發佈到本地倉庫

編寫完代碼後,先執行 1(clean)  再執行 2(deploy),  見下圖右側:

/**
 * String 工具類
 */
public class HunterStringUtil {
    /**
     * 如果被判斷的值是 null 則返回指定的字符串
     * @param obj
     * @param str
     * @return String
     */
    public static String emptyToString(Object obj,String str){
        return obj==null?"":obj.toString();
    }
}

執行結果

9、現在去 Nexus web 中查看本地倉庫

至此,把本地項目打包發佈到本地倉庫,操作完畢!

二、創建遠程倉庫、倉庫組及其使用

1、創建阿里雲遠程倉庫

創建結果

2、創建自定義倉庫組(把所有的倉庫加入自定義倉庫組-可自主選擇)

創建結果

3、測試本地倉庫組

打開 IDEA  創建項目(項目創建過程:略)

配置項目的 pom.xml 文件

    <repositories>
        <repository>
            <id>nexus-admin</id>
            <name>nexus-admin Repository</name>
            <url>http://192.168.11.16:8081/repository/nexus-admin/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus-admin</id>
            <name>nexus-admin Repositories</name>
            <url>http://192.168.11.16:8081/repository/nexus-admin/</url>
        </pluginRepository>
    </pluginRepositories>

4、創建測試類

由此可見,可在項目中自動引用本地倉庫中的 jar 包。

創建自定義倉庫組並在項目中引用已上傳至本地倉庫中的 jar 包操作完畢!

 

 

至此,Nexus 部分私服配置操作完畢!後期或有補充!

希望能夠對您有所幫助!

 

參考地址:

https://blog.csdn.net/u012637358/article/details/93832491

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