Spring Boot Maven插件包含资源

时间:2018-02-20 19:53:02

标签: maven spring-boot spring-boot-maven-plugin

实施例

是否有可能以某种方式配置spring boot maven插件以包含来自依赖项的资源。

E.g。如果在我的春季启动项目中,我有:

<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 boot JAR的boot BOOT-INF/classes/目录中,以便像自动配置这样的东西可以把它拿起来。

真实世界

在现实世界中,我试图这样做:

  • thymeleaf模板(例如我的依赖项JAR提供HTML模板文件,但在部署的引导jar中,这些模板未解析)
  • liquibase更改日志文件(我的依赖项包括更改日志文件,但这些文件尚未执行 - 我认为liquibase autoconfig找不到更改日志文件,因为它不在src/main/resources的{​​{1}}中引导JAR)。

1 个答案:

答案 0 :(得分:11)

我认为这个问题的解决方案与solution for another question you asked非常相似。

您可以在Spring Boot模块中使用unpack的{​​{1}}目标:

maven-dependency-plugin

这会将资源从<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> 的{​​{1}}复制到module-a目录。我在GitHub上发布了一个更完整的示例。

相关问题