Running specific Maven Test with JVM Args

21 09 2007

I have some long running tests in search, but I wouldnt want anyone to run them as part of the normal build. The tests dont have the word Test in the classname which prevents them from running, but they can be invoked on the command line with -Dtest=classname

mvn -Dtest=SearchSoak test

Also I have found that its necessary sometimes to add jvm args to the unit test, reconfiguring the Surefire plugin makes this possible, in the pom

    <maven.test.jvmargs> </maven.test.jvmargs>

And then to run with a heap dump and YourKit connection

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Applications/YourKit Java Profiler"mvn -Dtest=SearchSoak \
   -Dmaven.test.jvmargs='-XX:+HeapDumpOnOutOfMemoryError -agentlib:yjpagent' \



5 responses

30 01 2009
Eirik R. Larsen

Instead of specifying in settings.xml you can specify instead, which is read by the surefire plugin. That way you don’t need to configure the surefire plugin per project in pom.xml.

If you need to override the setting on the commandline you type

mvn clean install -DargLine=[jvm args]


16 04 2009
Yuen-Chi Lian

Hi there,

Thanks heaps.


17 08 2012

Is there a way to specify several properties like:

mvn2.1 test -DargLine=”-Dproperty=test -Dproperty2=test2″

Bacause when I’m trying to execute next code it returns not what I’m expected

System.out.println(System.getProperty(“property”)); // test -Dproperty2=test2

System.out.println(System.getProperty(“property2”)); // null

17 08 2012

This is a pure guess, but play around with quoting

mvn2.1 test -DargLine='-Dproperty="test" -Dproperty2="test2"'

might work, it looks like maven is interpreting

mvn2.1 test -DargLine="-Dproperty=test -Dproperty2=test2"


-Dproperty="test -Dproperty2=test2"

20 08 2012

Thank you for the reply. It is some parsing problem in TeamCity…
From the cmd it works fine,

%d bloggers like this: