Maven继承父模块资源 [英] Maven inherit parent module resources
问题描述
在Maven中,是否可以从父项目中加载子模块中的资源?
In Maven, is it possible to load resources in a child module from the parent project?
parent project
---child module 1
---child module 2
我在父项目src/main/resources
中有资源,希望将其提供给子项目.理想情况下,子项目可以覆盖任何资源.
I have resources in the parent project src/main/resources
which I would like to be made available for the child projects. Ideally the child projects could override any of the resources.
推荐答案
利用库中的资源和/或覆盖库中的资源的最佳方法是将这些资源放在类路径中.例如例如,所有通用配置都存储在common-config.properties
中,并放置在父项目的src/main/resources
中.如果继承项目需要覆盖配置,则继承项目可以简单地将覆盖的文件放在其src/main/resources
下.在运行时,代码应在类路径中查找此属性,然后将加载正确的文件.
Best way to leverage resources from a library and / or override resources that are in the library is to put those resources in the class path. For e.g. say all common configuration are stored in common-config.properties
and placed in the src/main/resources
of the parent project. If an inheriting project needs to override the configuration, inheriting project can simple place the overridden file under its src/main/resources
. In runtime, code should look for this property in classpath and right file will get loaded.
这篇关于Maven继承父模块资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!