一个人如何在Spring Boot Maven多模块项目中包含来自另一个模块的资源 [英] How Can One Include Resources From Another Module In A Spring Boot Maven Multi Module Project

查看:334
本文介绍了一个人如何在Spring Boot Maven多模块项目中包含来自另一个模块的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot Mavel多模块项目.

I have a spring boot mavel multi-module project.

如果spring boot模块依赖于模块A,并且在模块Asrc/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-pluginunpack目标:

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.

这篇关于一个人如何在Spring Boot Maven多模块项目中包含来自另一个模块的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆