如何将maven项目打包上传到私服

比如我们想要把项目通过maven生产源码包和文档包并发布到自己的私服上,有两个maven插件可以做到这些工作,一个是maven-source-plugin,另一个是maven-javadoc-plugin。

一:首先在你的项目的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>

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

上门的id和pom.xml 中对应distributionManagement-> repository 的ID ,用户名和密码需要在nexus 中配置

二:执行maven命令,mvn clean package,执行完成后就会生成相应的jar包文件

三:如果你还需要发布到自己的私服,那么就再执行一条命令:mvn deploy就可以发布到你自己的私服上了,这样同项目组的人员就可以查看你的项目的源码和文档了!

执行 mvn install,maven会自动将source install到repository 。

执行mvn deploy –Dmaven.test.skip=true,maven会自动将source deploy到remote-repository 。

原文地址:https://www.cnblogs.com/winner-0715/p/7495179.html