Maven打包分包(亲测Springboot和Solon框架都可以)

每次打包jar文件太大了,所以找到了这个配置

示例

这是一个solon2资源,目录有三个文件
1701843056490.jpg

配置

不需要打包到config文件夹的文件(支持统配)
1701843430530.jpg
不需要打包到jar内的文件(支持统配)
1701843430539.jpg

结果

1701843184726.jpg
config的文件
1701843253419.jpg
jar内的文件
1701843329382.jpg

pom在这

     <build>
        <plugins>
            <!-- 依赖包插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/app/lib</outputDirectory>
                            <!-- 是否不包含间接依赖 -->
                            <excludeTransitive>false</excludeTransitive>
                            <!-- 忽略版本 -->
                            <stripVersion>false</stripVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- maven资源文件复制插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>copy-config</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/app/config</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <filtering>false</filtering>
                                    <!-- 不需要打包到config的文件 -->
                                    <excludes>
                                        <exclude>**/*.xdb</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 可执行jar插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <outputDirectory>${project.build.directory}/app/bin</outputDirectory>
                    <!-- 这些配置将写入到MANIFEST.MF文件中 -->
                    <archive>
                        <!-- 指定程序入口 -->
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>../lib/</classpathPrefix>
                            <mainClass>com.xcmrfc.openapi.OpenApiApplication</mainClass>
                        </manifest>
                        <!-- (配置文件外置目录) -->
                        <manifestEntries>
                            <Class-Path>../config/</Class-Path>
                        </manifestEntries>
                    </archive>
                    <excludes>
                        <!-- 不需要打包到jar的文件 -->
                        <exclude>**/*.yml</exclude>
<!--                        <exclude>**/*.xdb</exclude>-->
                        <exclude>**/*.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>