I'm running a unit test in NetBeans 7.2. using Maven.
How to set a system property?
I've tried adding the property using:
Project Properties > Run > JVM arguments
but it doesn't make a difference. I think it may have something to do with JUnit running in a different JVM or something?
Since the NetBeans integrates to the Maven quite well, It will use the maven configuration (POM) for handling the lifecycle, e.g. clean, build(install) and test. For example, when you right click at the project and select "Clean and Build", you may see the something like the following:
cd D:\temp\prj\netbeans\dummy;
JAVA_HOME=C:\\Java.Application\\Sun\\Java\\jdk1.6.0_31 "\"
C:\\Java.Application\\Sun\\NetBeans 7.1\\java\\maven\\bin\\mvn.bat\""
clean install
I'm using the maven-surefire-plugin for setting/passing the system properties as the following:-
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<encoding>UTF-8</encoding>
<systemProperties>
<property>
<name>DEF</name>
<value>456</value>
</property>
</systemProperties>
<argLine>-DABC=123</argLine>
</configuration>
</plugin>
</plugins>
</build>
You may see that there are 2 positions for passing the system properties as the following:
- The systemProperties tag
- The argLine tag
Regarding to the argLine tag, you can pass, not only the system properties, but also any further JVM arguments, e.g. -Xms, -Xmx as well.
You may see further information about the system properties here and the argLine here.
来源:https://stackoverflow.com/questions/10851534/how-to-set-system-properties-using-netbeans-7-2-and-maven