System properties specified on the command line do not get passed to unit tests as they are running in a different JVM instance. To enable specific system properties that shall get passed you can insert the following into the maven-surefire-plugin section of the build section in the pom.xml (This has been tested with version 2.9):

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <systemPropertyVariables>
          <example.property>${example.property}</example.property>
        </systemPropertyVariables>
      </configuration>
    </plugin>
    ...
  </plugins>
  ...
</build>

You can then pass the argument by calling

mvn -Dexample.property=examplevalue test

Meta

Created:

Updated: 12/15/2015 23:12