如何使用Netbeans 7.2和Maven设置系统属性? [英] How to set system properties using Netbeans 7.2 and Maven?

查看:302
本文介绍了如何使用Netbeans 7.2和Maven设置系统属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NetBeans 7.2中运行单元测试。使用Maven。

I'm running a unit test in NetBeans 7.2. using Maven.

如何设置系统属性?

我尝试使用以下方法添加属性:

I've tried adding the property using:

项目属性>运行> JVM参数

Project Properties > Run > JVM arguments

但它没有什么区别。我认为它可能与在不同JVM中运行的JUnit有什么关系?

but it doesn't make a difference. I think it may have something to do with JUnit running in a different JVM or something?

推荐答案

由于NetBeans集成到Maven很好,它将使用maven配置(POM)来处理生命周期,例如清理,构建(安装)和测试。例如,当您右键单击项目并选择清理并构建时,您可能会看到如下内容:

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

我正在使用 maven-surefire-plugin 用于设置/传递系统属性如下: -

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>

您可能会看到有2个位置用于传递系统属性,如下所示:

You may see that there are 2 positions for passing the system properties as the following:


  1. systemProperties 标记

  2. argLine 标记

  1. The systemProperties tag
  2. The argLine tag

关于 argLine标记 ,您不仅可以通过系统属性,还有任何进一步的JVM参数,例如-Xms,-Xmx。

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.

您可能会看到有关系统属性的更多信息这里和argLine 这里

You may see further information about the system properties here and the argLine here.

这篇关于如何使用Netbeans 7.2和Maven设置系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆