nexus私服应用上传与下载

提示:在操作本案列之前需要安装maven+nexus!

1、下载

第一步:

配置maven > conf > settings.xml 文件

在文件servers标签里添加代码:

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

id: nexus中Repository名称,分为snapshots,releases等等,别去需要在配置
username:  nexus中登陆账户名
password:  nexus中登陆账户密码

第二步:

在maven指定项目的 pom.xml中配置,这里我配置ssm_dao项目,目的是把项目上传到私服中

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

id :  与上述server中的id名称一致

url: 上传的地址,这个连接可以在nexus中获取

 第三步:

在maven生命周期中进行发布(deploy)上传

上传之后的效果如图:

2、下载

第一步:

 在maven > conf > settings.xml文件profiles标签中配置

<!-- 下载jar包配置 -->
<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>


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

配置后效果如图:

 第二步:

测试下载之前需要把本地仓库的对应依赖删除掉,这里我以ssm_dao项目进行操作

 删除在指定依赖ssm_dao项目中进行测试运行,此时maven找不到本地参考的坐标后会自动向nexus私服中下载相应的依赖架包

原文地址:https://www.cnblogs.com/M87-A/p/14871608.html