springboot项目打组合包(依赖包和可执行包)

springboot项目打包,可以当依赖包用也可以当可执行包用

1、项目 java目录下新建目录assembly

添加文件assembly.xml

<?xml version="1.0" encoding="utf-8"?>
<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <!-- id 标识符,添加到生成文件名称的后缀符。如果指定 id 的话(这里指定的是项目的版本),目标文件则是 ${artifactId}-${id}.jar。【如yigo-core.jar】 -->
    <id>jar-with-dependencies</id>

    <!-- 指定打包格式。maven-assembly-plugin插件支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式 -->
    <formats>
        <format>jar</format>
    </formats>

    <!-- 指定打的包是否包含打包层目录(比如finalName是yigo-core,当值为true,所有文件被放在包内的yigo-core目录下,否则直接放在包的根目录下)-->
    <includeBaseDirectory>false</includeBaseDirectory>



    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
        </dependencySet>
    </dependencySets>



    <!--    &lt;!&ndash; 指定将工程依赖的包打到包里的指定目录下 &ndash;&gt;-->
<!--    <dependencySets>-->
<!--        <dependencySet>-->
<!--            <useProjectArtifact>true</useProjectArtifact> &lt;!&ndash; 指定打包时是否包含工程自身生成的jar包 &ndash;&gt;-->
<!--            <outputDirectory>lib</outputDirectory> &lt;!&ndash; 指定将这些依赖包打到包里lib目录下 &ndash;&gt;-->
<!--            <scope>runtime</scope> &lt;!&ndash; 用于管理依赖的部署,runtime表示只在运行时使用 &ndash;&gt;-->
<!--        </dependencySet>-->
<!--    </dependencySets>-->

    <containerDescriptorHandlers>
        <containerDescriptorHandler>
            <handlerName>metaInf-spring</handlerName>
        </containerDescriptorHandler>
    </containerDescriptorHandlers>

    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/classes</directory>
            <outputDirectory>.</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

2、pom.xml中添加

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>release</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>false</addClasspath>
                                    <classpathPrefix>lib/</classpathPrefix>
                                    <classpathLayoutType>repository</classpathLayoutType>
                                    <mainClass>com.demo.first.FirstApplication</mainClass>
                                </manifest>
                            </archive>
                            <appendAssemblyId>true</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值