如何在构建时将依赖项中的静态资源包含在spring-boot-fat jar中



我有一个spring-boot应用程序,它的UI是单独构建的,并作为依赖项添加到我的应用程序中。现在,我想在构建时解压依赖项并将其添加到spring-boot应用程序的资源文件夹中,使其成为fat-jar的一部分。有人能指导我如何使用spring-boot-maven插件来实现这一点吗。

注意:该项目正在使用maven来构建

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>nflow-explorer</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>io.nflow</includeGroupIds>
<includeArtifactIds>nflow-explorer</includeArtifactIds>
<outputDirectory>
${project.build.directory}/resources/main/static/explorer
<!-- or: ${project.basedir}/wherever/you/want/it -->
</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

您不必解压缩JAR。

只需使用Maven资源插件http://maven.apache.org/plugins/maven-resources-plugin/index.html

您可以指定要包含的目录,如下所示:

<project>
...
<build>
...
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
...
</build>
...
</project>

最新更新