上传jar包依赖到maven私服的操作方法

1、配置maven的settings文件

<servers>

    <server>

        <id>releases</id>

        <username>deployment</username>

        <password>deployment123</password>

    </server>

    <server>

        <id>snapshots</id>

        <username>deployment</username>

        <password>deployment123</password>

    </server>

</servers>

其中id对应着nexus私服的仓库id,如果要上传到其它仓库,同样需要在settings文件中进行相关配置即可。

 

用户名和密码对应nexus中设置的用户名密码,在Security->Users中,在对应的用户名上右键-> Set Password进行设置。

 

2、修改仓库权限

需要将对应的仓库权限改成Allow Redeploy,点击仓库名->Configuration

 

3、配置pom.xml文件

<repositories>

    <repository>

        <id>nexus</id>

        <name>nexus</name>

        <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>

        <releases>

            <enabled>true</enabled>

        </releases>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

    </repository>

</repositories>

 

<pluginRepositories>

    <pluginRepository>

        <id>nexus</id>

        <name>nexus</name>

        <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>

        <releases>

            <enabled>true</enabled>

        </releases>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

    </pluginRepository>

</pluginRepositories>

 

 

<distributionManagement>

    <repository>

        <id>releases</id>

        <name>User Project Release</name>

        <url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>

    </repository>

       <snapshotRepository>

          <id>snapshots</id>

          <name>User Project SNAPSHOTS</name>

        <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>

       </snapshotRepository>

</distributionManagement>

 

4、上传jar包命令

mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=jdbc14 -Dversion=1.0.0 -Dpackaging=jar -Dfile=C:\Users\wangc\.m2\repository\mysql\mysql-conn

ector-java\5.1.42\mysql-connector-java-5.1.42.jar -Durl=http://127.0.0.1:8081/nexus/content/repositories/releases/ -DrepositoryId=releases -X

其中DgroupId和DartifactId构成了该jar包在pom.xml的坐标,项目就是依靠这两个属性定位。

Dfile表示需要上传的jar包的绝对路径。 

Durl私服上仓库的位置,打开nexus->repositories菜单,可以看到该路径。 

DrepositoryId表示仓库id,在nexus的配置信息中可以找到。

-X表示输出全部日志,如果有报错可以看到详细的报错信息

 

注意:如果报错Cannot deploy artifact from the local repository,是因为要安装的jar和pom不能是位于本地repository的目录下,将要安装的jar和pom copy到其它目录再安装。

除了可以上传jar包之外,还可以pom

mvn deploy:deploy-file -Dfile=[your file] -DgroupId=[xxxx] -DartifactId=[xxxx] -Dversion=[xxxx] -Dpackaging=[pom|jar|other] -DrepositoryId=[id] -Durl=[repo url]

 

 

 

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值