【问题标题】:Spring Boot Maven Plugin Include ResourcesSpring Boot Maven 插件包含资源
【发布时间】:2018-07-31 06:46:56
【问题描述】:

示例

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

例如如果在我的 Spring Boot 项目中我有:

  <dependency>
    <groupId>co.company</groupId>
    <artifactId>example</artifactId>
  </dependency>

在那个 JAR 文件中有一个属性文件,例如 example.properties

jar -tf example.jar | grep example.properties | wc -l

结果为 1。

但是,当我构建 Spring Boot JAR 时,此属性文件并未添加到 src/main/resources。包含它的 JAR 包含在 BOOT-INF/lib/example.jar

但是,就我而言。我想把src/main/resources的内容解压到spring boot JAR的bootBOOT-INF/classes/目录中,这样自动配置之类的东西就可以提取出来了。

现实世界

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

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

【问题讨论】:

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


    【解决方案1】:

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

    您可以在 Spring Boot 模块中使用 maven-dependency-pluginunpack 目标:

    <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-moduleBOOT-INF 目录。我在GitHub 上发布了一个更完整的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2016-01-16
      • 2013-03-09
      • 2017-03-26
      • 1970-01-01
      相关资源
      最近更新 更多