Filter resources in an Maven multi module project

The Maven project I’m working on has multiple modules and as I needed different configurations for different deployment platforms I created additional configuration modules. This approach really becomes bad when adding a new configuration parameter or changing some Spring Bean definitions because it has to be done in every single configuration module.

The Maven resource filter avoids this situation by replacing variable keywords in any text file you need with values from specified property files. This makes it possible to have only one module with all the configurations, all thats needed are different property files which are used based on the Maven Profile that is used. Here’s the POM from the configuration module:

  • 18 – 34: define profiles for different deployment platforms, one for localhost development and one for the production system. Starting maven with “-P” will use the “” to filter the resources.

  • 38 – 41: in the filter elements the property files are specified which contain the values that gonna be used.

  • 42: you can specify as many resource elements as needed

  • 44: the directory for this resource element.

  • 45: boolean flag for activating the filtering or just copying the resources without filters.

  • 46 – 49: specify expressions which match the files that shall be filtered.

  • 51 – 59: all other resources than the excluded once should just be copied without any filtering

  • 61 – 69: here resources can be filtered that are only necessary for testing.