2

In Maven, is it possible to load resources in a child module from the parent project?

parent project
   ---child module 1
   ---child module 2

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    Unclear. The parent project must be of `pom` packaging so there is really no such thing as "project resources" for this type of packaging. Could you post your real use-case? – Tunaki Nov 17 '15 at 07:08
  • 2
    I think its quite clear. A parent project where the developer puts his resources, and the child modules would inherits by default during the packaging phase. I just made a test myself and the package doesnt put resources of the parent into the target classpath of the child. – Zakaria Bouazza Oct 15 '17 at 09:11

1 Answers1

2

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.