Environment Variable with Maven

Environment Variable with Maven

You can just pass it on the command line, as

mvn -DmyVariable=someValue install

[Update] Note that the order of parameters is significant - you need to specify any options before the command(s).[/Update]

Within the POM file, you may refer to system variables (specified on the command line, or in the pom) as ${myVariable}, and environment variables as ${env.myVariable}. (Thanks to commenters for the correction.)

Update2

OK, so you want to pass your system variable to your tests. If - as I assume - you use the Surefire plugin for testing, the best is to specify the needed system variable(s) within the pom, in your plugins section, e.g.

<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
...
<configuration>
...
<systemPropertyVariables>
<WSNSHELL_HOME>conf</WSNSHELL_HOME>
</systemPropertyVariables>
</configuration>
</plugin>
...
</plugins>
</build>

How to add Maven to the Path variable?

The problem get solved when i edit the path variable with ;%Maven_Home%\bin; so i should add the ; before and after it.

How to refer environment variable in POM.xml?

Check out the Maven Properties Guide...

As Seshagiri pointed out in the comments, ${env.VARIABLE_NAME} will do what you want.

I will add a word of warning and say that a pom.xml should completely describe your project so please use environment variables judiciously. If you make your builds dependent on your environment, they are harder to reproduce

MAVEN: How Do I Pass a -D System Variable to Test

You should be able to use a Maven Property in your pom.xml

Check the Properties section of http://maven.apache.org/settings.html#Activation

or maybe this question might help How to identify and set a missing environment property in Maven?

Edit: You can also set an environment variable in the section of a plugin like the surefire plugin: Environment Variable with Maven



Related Topics



Leave a reply



Submit