一个人如何在Spring Boot Maven多模块项目中包含来自另一个模块的资源
我有一个Spring Boot Mavel多模块项目.
I have a spring boot mavel multi-module project.
如果spring boot模块依赖于模块A
,并且在模块A
的src/main/resources
文件夹中有一个属性文件或我想捆绑在最终的spring boot应用程序中的其他资源,我该如何实现这个.
If the spring boot module depends on module A
and in the src/main/resources
folder of module A
there is a properties file or some other resource that I want bundled in the final spring boot app, how can I achieve this.
当前,如果我在模块A JAR上运行jar -tf
,它将包含文件:
Currently, if I run jar -tf
on the module A JAR it includes the file:
jar -tf module-a/target/module-a-0.0.1-SNAPSHOT.jar | grep changelog
db/changelog/
db/changelog/db.changelog-master.yaml
但是:
jar -tf boot-module/target/boot-module-0.0.1-SNAPSHOT.jar | grep changelog | wc -l
0
预先感谢您的任何建议.
Thanks in advance for any advice.
如果我正确理解了您的要求,我相信您可以在Spring Boot模块中使用maven-dependency-plugin
的unpack
目标:
If I understand your requirements correctly, I believe you can use the unpack
goal of the maven-dependency-plugin
in your Spring Boot module:
<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/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这会将资源从module-a
复制到boot-module
.我已经在 GitHub 上发布了完整的示例.
That will copy the resources from module-a
to boot-module
. I've posted a complete example on GitHub.