How to override variable defined in the POM with specific value at the time of mvn execution?


In an environment with multiple Web Container settings we sometimes need to correctly point to the application deploy directory that may be in different directories depending on the Operating System used and the package manager (apt-get on Ubuntu, homebrew on Mac OS, etc.). In addition we may need to install more than one instance of the application on a machine (Test, Homologation, Production, etc.). For this we need to override a certain property defined in the POM that points to the deploy directory.

What is the best way to do this?

asked by anonymous 09.03.2014 / 19:04

1 answer


To override a property defined in the POM use the parâmetro -D typical of any Java application when invoking mvn

For example to deploy assets shared by applications to a TEST directory:

mvn -P deployShared package  -Dshared_dir=/usr/local/Cellar/tomcat/7.0.47/shared

In this example we are overwriting shared_dir during the package phase. This variable is used by the deployShared profile defined in the POM to copy the files to the Tomcat environment (version 7.0.47) used for Test .

The same POM can be used to deploy to the Homologation environment as follows:

mvn -P deployShared package -Dshared_dir=/usr/local/tomcat-7.0.47-homolog/shared

And so on.

The profile deployShared uses maven-dependency-plugin and looks like this:

09.03.2014 / 19:17