将maven项目打包上传到私服

1. 配置私服账户密码

在maven 的setting.xml 中配置用户名和密码:

<servers>
    <server>
        <username>deployment</username>
        <password>deploy123</password>
        <id>nexus-release</id>
    </server>
    <server>
        <username>deployment</username>
        <password>deploy123</password>
        <id>nexus-snapshots</id>
    </server>
</servers>

2. 配置项目pom.xml

如果有parent 只需在parent 中的pom.xml 中配置,没有则在本项目的pom.xml 配置即可

<distributionManagement>
    <repository>
        <id>nexus-release</id>
        <url>http://192.168.0.247/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <url>http://192.168.0.247/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>
 
<build>
    <plugins>
        <!-- 生成sources源码包的插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <!--意思是在什么阶段打包源文件-->
                    <phase>package</phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

上面的id【nexus-releasenexus-snapshots】和pom.xml 中对应distributionManagement-> repository 的ID ,用户名和密码需要在nexus 中配置,这里定义了两个Repository,可以根据项目的version后缀自动选择发布到哪一个仓库,例如version是0.0.1-SNAPSHOT,则会发布到snapshotRepository里,具体可以观察打包的maven日志。

3. 执行打包发布命令

  • 执行 maven命令,mvn clean package,执行完成后就会生成相应的jar包文件
  • 如果你还需要发布到自己的私服,那么就再执行一条命令:mvn deploy就可以发布到你自己的私服上了,这样同项目组的人员就可以查看你的项目的源码和文档了!
  • 执行 mvn install,maven会自动将source install到repository 。
  • 执行 mvn deploy –Dmaven.test.skip=true,maven会自动将source deploy到remote-repository 。

4. 手动打包发布

在jar包仓库目录下执行以下命令:

mvn deploy:deploy-file -DgroupId=[0] -DartifactId=[1] -Dversion=[2] -Dpackaging=jar -Dfile=[3] -Durl=[4] -DrepositoryId=[5] -DpomFile=[6]
  • [0] : groupId
  • [1] : artifactId
  • [2] : version
  • [3] : jar包名称
  • [4] : 仓库地址
  • [5] : 仓库ID,这里和setting.xml 中配置的serverId对应
  • [6] : pom名称

例如:

mvn deploy:deploy-file -DgroupId=com.alipay.sdk -DartifactId=alipay-sdk-java -Dversion=4.1.17.ALL -Dpackaging=jar -Dfile=alipay-sdk-java-4.17.9.ALL.jar -Durl=http://172.16.1.22:8081/nexus/content/repositories/snapshots -DrepositoryId=Snapshots -DpomFile=alipay-sdk-java-4.17.9.ALL.pom

image-20220523163357510

posted @   waveblog  阅读(313)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示