将项目打包至私有maven仓库

本文详细介绍如何配置Maven私有仓库,包括设置账号密码、仓库地址,以及在pom.xml中指定仓库,最后通过deploy命令将项目部署至远程仓库。

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

1.下载并安装maven

2.打开conf目录的settings.xml文件,找到servers节点并添加私有仓库的id、用户名、密码

<!-- 配 上传的账号和密码 -->
<!-- 发布到发行版本的仓库中,即正式版本仓库 -->
   <server>
       <id>releases</id>
       <username>用户名</username>
       <password>密码</password>
   </server>
<!-- 发布到快照版本的仓库,即测试版本仓库 -->
   <server>
       <id>snapshots</id>
       <username>用户名</username>
       <password>密码</password>
   </server>

3.找到profiles节点配置私有仓库地址
 

<profile>
      <id>kn-dev</id>
      <repositories>
        <repository>
            <id>public</id>
            <name>Public Repositories</name>
            <url>http://仓库地址加端口/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    
    <pluginRepositories>
        <pluginRepository>
           <id>public</id>
           <name>Public Repositories</name>
           <url>http://仓库地址加端口/nexus/content/groups/public/</url>
           <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    </profile>

4.在profiles节点后激活该配置

<activeProfiles>
    <activeProfile>kn-dev</activeProfile>
</activeProfiles>

 

5.在maven项目里面的pom.xml配置要发布的仓库地址

<distributionManagement>
    <!-- 发布到快照版本的仓库,即测试版本仓库 -->
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://仓库地址加端口/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
    <!-- 发布到发行版本的仓库中,即正式版本仓库 -->
    <repository>
        <id>releases</id>
        <url>http://仓库地址加端口/nexus/content/repositories/releases</url>
    </repository>
</distributionManagement>

6.执行deploy命令即可将项目打包至远程仓库

mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=D:\project\helloworld.jar -DgroupId=com.itcaset.test -DartifactId=maven-test -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -DrepositoryId=public -Durl=http://192.168.0.112/repository/roy_privrepository_snapshots/

-Dmaven.test.skip=true //跳过编译、测试

-Dfile=D:\project\helloworld.jar //jar包文件地址,绝对路径

-DgroupId=com.itcaset.test //gruopId--pom坐标,自定义

-DartifactId=maven-test //artifactId--pom坐标,自定义

-Dversion //版本号

-Dpackaging //打包方式

-DrepositoryId //远程库服务器ID

-Durl //远程库服务器地址

idea可以在maven插件运行deploy

项目的version如果是以SNAPSHOT结尾,则项目会发布到快照仓库,否则发布到正式版本仓库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值