IDEA 部署项目jar至私有maven库

本文介绍了如何使用IntelliJ IDEA将Java项目打包为jar,并上传到私有Maven仓库。首先,需要在pom.xml中配置distributionManagement节点,指定仓库URL。然后,在mavensettings.xml中添加对应的服务器和镜像配置,包括用户名和密码。完成配置后,通过IDEA的Maven面板执行clean、package和deploy目标,即可将jar包上传至私有仓库。当需要更新jar包时,记得修改version并重新上传。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IDEA 部署项目jar至私有maven库

1.在需要上传项目的pom.xml文件添加distributionManagement节点。

	<distributionManagement>
        <repository>
            <!--此名称要和maven settings.xml中设置的ID一致 -->
            <id>nexus-releases</id>
            <url>http://10.0.12.124:8081/nexus/content/groups/public</url>
        </repository>
        <snapshotRepository>
            <!--此名称要maven settings.xml中设置的ID一致 -->
            <id>nexus-snapshots</id>
            <url>http://10.0.12.124:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
  • 注意:IDEA设置的maven settings.xml文件中需要添加对应maven库配置。

    在标签中添加:

    	<server>  
          <id>nexus-releases</id>  
          <username>admin</username>  
          <password>xxxxx</password>  
        </server>  
        <server>  
          <id>nexus-snapshots</id>  
          <username>admin</username>  
          <password>xxxxx</password>  
        </server>
    

    在标签中添加:

     	<mirror>   
          <id>nexus-releases</id>   
          <mirrorOf>*</mirrorOf>   
          <url>http://10.0.12.124:8081/nexus/content/groups/public</url>   
        </mirror>  
        <mirror>   
          <id>nexus-snapshots</id>   
          <mirrorOf>*</mirrorOf>   
          <url>http://10.0.12.124:8081/nexus/content/repositories/snapshots</url>   
        </mirror>
    

2.IDEA中打包项目jar包并上传。

  • 点击窗口右侧maven标签,点开项目的lifecycle。

  • 双击clean清理项目。

  • 双击package生成jar包。

  • 双击deploy上传jar包。

    需要引用jar包,只需要在pom文件添加依赖即可:

    <dependency>
        <groupId>com.xxxx.xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>xxxx</version>
    </dependency>
    

    groupId、artifactId、version对应项目打包时的pom文件描述。

  • 注意:jar包更新时,修改version号重新打包并上传。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值