David Williams
David Williams

Reputation: 8654

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

I'd like to set a system environment variable to be visible by Java code in the unit tests of a Maven project. I tried this:

mvn -Dfoo=bar clean package

But that doesn't seem to take. How do I accomplish this?

Upvotes: 0

Views: 9116

Answers (1)

jmcmahon
jmcmahon

Reputation: 630

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

Upvotes: 1

Related Questions