例子
是否可以以某种方式配置 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 Boot JAR 时,此属性文件未添加到
src/main/resources
.包含它的 JAR 包含在 BOOT-INF/lib/example.jar
中但是,就我而言。我想提取
src/main/resources
的内容进入开机BOOT-INF/classes/
spring boot JAR 的目录,以便自动配置之类的东西可以选择它。真实世界
在现实世界中,我正在尝试这样做:
src/main/resources
中)。 最佳答案
我认为这个问题的解决方案与 solution for another question you asked 非常相似。 .
您可以使用 unpack
maven-dependency-plugin
的目标在您的 Spring Boot 模块中:
<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-INF
您的 boot-module
的目录.我在 GitHub 上发布了一个更完整的示例.
关于maven - Spring Boot Maven 插件包含资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48893178/