Sharing Resources between Maven modules

(Recovered from my old Blog).

I needed to share resources between modules in a multi-module Maven project. The resources in question are configuration data files which are converted into objects via XStream (plus some Spring Bean configuration files). The reason they need to be shared is for instantiation within module-specific JUnit tests.

After some thinking and Googling around, I think I have come up with the ‘cleanest’ structure. My first thought was to put them into the parent module, but after messing around with configuration, I began to realise this was a bad idea.

My new solutions goes like this:

  • Create a new sub-module (called config or whatever)
  • Put a dependency to this new module in the pom.xml for all other modules
  • Even though these are test resources, put them in /src/main/resources so they are packaged into the jar (or obviously change the default packaging so it includes the /src/test/resources)

Quite clean I think.

Leave a Reply

Your email address will not be published. Required fields are marked *