maven_上傳到私服,以及從私服下載

公司由於沒有maven,自己又想用,於是乎,就自己搭了一個nexus

1、苦逼不多說,將本地jar文件上傳到maven

   需要在本機(客戶端windows)中的maven中的setting.xml添加這個:

  

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

  然後再項目中的pom.xml文件中添加:

  

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

  這個時候需要注意distributionManagement->repository->id要和mvn的setting.xml中server中的id一致。

  最後執行生命週期得到最後一個deploy。就可以上傳到私服

  

2.再說從私服中下載:

  你需要在mvn中的setting.xml文件中找到profiles標籤下添加:

<!-- 下載jar包配置 -->
    <profile> 
        <!--profile的id -->
        <id>dev</id>
        <repositories>
            <repository> <!--倉庫id,repositories可以配置多個倉庫,保證id不重複 -->
                <id>nexus</id> <!--倉庫地址,即nexus倉庫組的地址 -->
                <url>http://localhost:9081/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:9081/nexus/content/groups/public/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>

  在mvn的setting.xml中添加

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

  注意 activeProfiles->activeProfile 和profiles->profile->id一致

 然後就能下載了。

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