Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the mvn -D to set (multiple) properties in Maven via command line?

How to use the mvn -D in maven? How to set a property (or multiple properties) using it?

Are there any official articles for mvn -D?

I couldn't find one. Thanks.

like image 531
jiafu Avatar asked Jun 27 '13 00:06

jiafu


People also ask

How do I set system properties in Maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

How use mvn command line?

To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.

What is the use of mvn package command in Maven?

mvn package This command builds the maven project and packages them into a JAR, WAR, etc.

What are the commands used to execute Maven project using CMD?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.


1 Answers

The proper way to set a property via command-line using -D is:

mvn -DpropertyName=propertyValue clean package 
  • If propertyName doesn't exist in the pom.xml, it will be set.
  • If propertyName already exists in the pom.xml, its value will be overwritten by the one passed as argument via -D.

To send multiple variables, use multiple space delimited -Ds:

mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package 

You can check more details about properties in Maven: The Complete Reference. More specifically, in section: 6.1. Maven Command Line Options/6.1.1. Defining Properties.

Example:

If you have in your pom.xml:

<properties>     <theme>myDefaultTheme</theme> </properties> 

Then mvn -Dtheme=halloween clean package would overwrite themes value during this execution, having the effect as if you had:

<properties>     <theme>halloween</theme> </properties> 
like image 192
acdcjunior Avatar answered Oct 05 '22 19:10

acdcjunior