Search code examples
mavenmoduleresourcespom.xmlmaven-module

Maven inherit parent module resources


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.


Solution

  • 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.