1. pom文件添加

<build>
    <plugins>
        <!--spring boot 打jar包分离lib和resources-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>src/main/resources/assembly.xml</descriptor>
                </descriptors>
                <outputDirectory>${project.build.directory}/dist/</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <!--名字任意 -->
                    <id>make-assembly</id>
                    <!-- 绑定到package生命周期阶段上 -->
                    <phase>package</phase>
                    <goals>
                        <!-- 只运行一次 -->
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- 打包成jar文件,并指定lib文件夹以及resources资源文件夹 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <!-- false:生成的jar中,不要包含pom.xml和pom.properties这两个文件-->
                    <addMavenDescriptor>true</addMavenDescriptor>
                    <manifest>
                        <!--项目启动类-->
                        <mainClass>com.zhuye.zlonline.person.PersonApplication</mainClass>
                        <!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->
                        <classpathPrefix>lib/</classpathPrefix>
                        <!--true:是否要把第三方jar放到manifest的classpath中-->
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <!--加载静态资源-->
                        <Class-Path>./</Class-Path>
                    </manifestEntries>
                </archive>
                <!--过滤掉不希望包含在jar中的文件-->
                <excludes>
                    <exclude>**/js/zlonline/.idea/**</exclude>
                    <exclude>**/js/back/**</exclude>
                    <exclude>**/js/zlonline/node_modules/**</exclude>
                    <exclude>**/js/zlonline/src/**</exclude>
                    <exclude>**/js/zlonline/tools/**</exclude>
                    <exclude>**/js/zlonline/build/**</exclude>
                    <exclude>**/js/zlonline/example/**</exclude>
                    <exclude>**/js/zlonline/*.json</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

2. resource下新建 assembly.xml

3. assembly.xml中添加

<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>distribution</id>

    <!--输出格式 zip 最终结果生成zip -->
    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>

    <!--设置需要输出文件-->
    <fileSets>
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>./</outputDirectory>
            <excludes>
                <exclude>/static/js/zlonline/.idea/**</exclude>
                <exclude>/static/js/zlonline/node_modules/**</exclude>
                <exclude>/static/js/zlonline/src/**</exclude>
                <exclude>/static/js/zlonline/tools/**</exclude>
                <exclude>/static/js/zlonline/build/**</exclude>
                <exclude>/static/js/zlonline/example/**</exclude>
                <exclude>/static/js/zlonline/*.json</exclude>
                <exclude>/static/js/back/**</exclude>
            </excludes>
        </fileSet>

    </fileSets>

    <dependencySets>
        <dependencySet>
            <!--依赖包的输出目录-->
            <outputDirectory>/lib</outputDirectory>
            <scope>runtime</scope>
            <excludes>
                <exclude>${project.groupId}:${project.artifactId}</exclude>
            </excludes>
        </dependencySet>
        <dependencySet>
            <!--jar包的输出目录-->
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>${project.groupId}:${project.artifactId}</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

4. 打包

maven : install