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一致

 然后就能下载了。

猜你喜欢

转载自www.cnblogs.com/lxl-six/p/11247419.html