美文网首页
Spring Boot打包时分离资源文件和依赖包的配置

Spring Boot打包时分离资源文件和依赖包的配置

作者: 上杉丶零 | 来源:发表于2019-07-16 17:39 被阅读0次
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <!-- 不打包资源文件(配置文件和依赖包分开) -->
                <excludes>
                    <exclude>static/**</exclude>
                    <exclude>templates/**</exclude>
                    <exclude>*.yml</exclude>
                    <exclude>*.properties</exclude>
                    <exclude>*.xml</exclude>
                    <exclude>*.txt</exclude>
                </excludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>./lib/</classpathPrefix>
                        <useUniqueVersions>false</useUniqueVersions>
                        <!-- 指定入口类 -->
                        <mainClass>com.hwtk.ip.HwtkIpApplication</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>./resources/</Class-Path>
                    </manifestEntries>
                </archive>
                <outputDirectory>${project.build.directory}</outputDirectory>
            </configuration>
        </plugin>

        <!-- 该插件用于复制依赖包到指定的文件夹里 -->
        <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}/lib/</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- 该插件用于复制配置文件到指定的文件夹里 -->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <!-- <include>*.properties</include> -->
                                </includes>
                            </resource>
                        </resources>
                        <outputDirectory>${project.build.directory}/resources</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Spring Boot打包插件,把maven-jar-plugin打成的jar包重新打成可运行jar包 -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!-- 重写包含依赖,包含不存在的依赖,jar里没有pom里的依赖 -->
                <includes>
                    <include>
                        <groupId>null</groupId>
                        <artifactId>null</artifactId>
                    </include>
                </includes>
                <layout>ZIP</layout>
                <!-- 使用外部配置文件,jar包里没有资源文件 -->
                <addResources>true</addResources>
                <outputDirectory>${project.build.directory}/resources</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <!--配置jar包特殊标识 配置后,保留原文件,生成新文件 *-run.jar -->
                        <!--配置jar包特殊标识 不配置,原文件命名为 *.jar.original,生成新文件 *.jar -->
                        <!--<classifier>run</classifier> -->
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

相关文章

网友评论

      本文标题:Spring Boot打包时分离资源文件和依赖包的配置

      本文链接:https://www.haomeiwen.com/subject/gbntlctx.html