Spring 引导 Maven 插件包含资源
Spring Boot Maven Plugin Include Resources
例子
是否有可能以某种方式配置 spring boot maven 插件以包含来自依赖项的资源。
例如如果在我的 spring 引导项目中我有:
<dependency>
<groupId>co.company</groupId>
<artifactId>example</artifactId>
</dependency>
并且在该 JAR 文件中有一个属性文件,例如 example.properties
jar -tf example.jar | grep example.properties | wc -l
结果为 1。
但是,当我构建 spring 引导 JAR 时,此属性文件未添加到 src/main/resources
。包含它的 JAR 包含在 BOOT-INF/lib/example.jar
但是,就我而言。我想将 src/main/resources
的内容提取到 spring 引导 JAR 的引导 BOOT-INF/classes/
目录中,以便自动配置之类的东西可以提取它。
现实世界
在现实世界中,我正在尝试使用:
- thymeleaf 模板(例如,我的依赖 JAR 提供了 HTML 模板文件,但在部署的引导 jar 中,这些模板未解析)
- liquibase changelog 文件(我的依赖包括 changelog 文件,但这些文件没有执行 - 我假设 liquibase autoconfig 没有找到 changelog 文件,因为它不在引导 JAR 的
src/main/resources
中)。
我认为这个问题的解决方案与 非常相似。
您可以在 Spring 引导模块中使用 maven-dependency-plugin
的 unpack
目标:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>module-a</artifactId>
<version>${project.version}</version>
<includes>**/*.yaml</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/classes/BOOT-INF/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这会将资源从 module-a
复制到 boot-module
的 BOOT-INF
目录。我在 GitHub.
上发布了一个更完整的示例
例子
是否有可能以某种方式配置 spring boot maven 插件以包含来自依赖项的资源。
例如如果在我的 spring 引导项目中我有:
<dependency>
<groupId>co.company</groupId>
<artifactId>example</artifactId>
</dependency>
并且在该 JAR 文件中有一个属性文件,例如 example.properties
jar -tf example.jar | grep example.properties | wc -l
结果为 1。
但是,当我构建 spring 引导 JAR 时,此属性文件未添加到 src/main/resources
。包含它的 JAR 包含在 BOOT-INF/lib/example.jar
但是,就我而言。我想将 src/main/resources
的内容提取到 spring 引导 JAR 的引导 BOOT-INF/classes/
目录中,以便自动配置之类的东西可以提取它。
现实世界
在现实世界中,我正在尝试使用:
- thymeleaf 模板(例如,我的依赖 JAR 提供了 HTML 模板文件,但在部署的引导 jar 中,这些模板未解析)
- liquibase changelog 文件(我的依赖包括 changelog 文件,但这些文件没有执行 - 我假设 liquibase autoconfig 没有找到 changelog 文件,因为它不在引导 JAR 的
src/main/resources
中)。
我认为这个问题的解决方案与
您可以在 Spring 引导模块中使用 maven-dependency-plugin
的 unpack
目标:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>module-a</artifactId>
<version>${project.version}</version>
<includes>**/*.yaml</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/classes/BOOT-INF/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这会将资源从 module-a
复制到 boot-module
的 BOOT-INF
目录。我在 GitHub.