How to set system properties using Netbeans 7.2 and Maven?

天涯浪子 提交于 2019-12-08 02:27:38

问题


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?


回答1:


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:

  1. The systemProperties tag
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!