NetBeans-为从NetBeans启动的每个JVM设置系统属性 [英] NetBeans - setting System Properties for every JVM that is started from NetBeans

查看:219
本文介绍了NetBeans-为从NetBeans启动的每个JVM设置系统属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置由NetBeans(在Win 7上为NB 7.3.1)启动的每个JVM使用的系统属性?

Is there a way to set System Properties which are used for every JVM that is started by NetBeans (NB 7.3.1 on Win 7)?

在我所有的Maven项目中,我都使用Log4j,但需要一个log4j.properties文件,该文件要由系统属性-Dlog4j.configuration=file:/c:/log4j/log4j.properties

In all my maven projects I use Log4j wich needs a log4j.properties file, to where I want to point to by a System Property -Dlog4j.configuration=file:/c:/log4j/log4j.properties

我可以设置Maven的全局执行选项:工具>选项> Java> Maven>全局执行选项.但是,当我在NetBeans中运行特定的JUnit测试类(因​​此没有Maven)时,NetBeans将不会使用在全局执行选项"字段中设置的这些JVM系统属性.

I could set Global Execution Options for Maven: Tools > Options > Java > Maven > Global Execution Options. But then when I run a particular JUnit test class in NetBeans (thus without Maven), NetBeans won't use these JVM System Properties set in the Global Execution Options field.

同一问题是在NetBeans中运行Maven模块中的Main类时.要设置JVM系统属性,可以设置项目属性:"Main Class"和"VM Options".但是,仅当从maven模块的上下文菜单中使用运行"命令时,NetBeans才使用这些项目属性. (不幸的是,此菜单项没有快捷键(通常为Shift-F6).)

Same issue is when a Main class in a Maven module is run in NetBeans. To set JVM System Properties there are Project Properties which could be set: 'Main Class' and 'VM Options'. But these Project Properties are only used by NetBeans when the 'Run' command is used from the context menu of the maven module. (Unfortunaly this menu item doesn't have a shortcut key (normaly Shift-F6)).

我通过设置系统变量JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties来解决此问题.

I have worked around this by setting a System Variable JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties.

修改
对于我遇到的相同问题,提出了一个问题:项目属性">生成">编译">保存时编译") ).在那种情况下,NetBeans似乎不使用Maven.有关CoS的更多信息: http://wiki.netbeans.org/FaqCompileOnSave

Edit
A question was asked for the same problem I ran in to: How to make Netbeans use specific JVM parameters when running tests? In my case the problem was caused by the option Compile on Save which I had swiched on (File > Project Properties > Build > Compile > Compile On Save). In that case it seems that NetBeans doesn't use Maven. For further info about CoS: http://wiki.netbeans.org/FaqCompileOnSave

推荐答案

nbproject文件夹中有一个名为project.properties的文件.在此文件中,您可以执行GUI菜单中没有的许多配置.我不知道确切该放置什么以实现您想要的,但是我在我的一个NetBeans项目配置中找到了它:

There's a file called project.properties in the nbproject folder. In this file there is a lot of configurations you can do that are not in the GUI menus. I don't know exactly what to put there to achieve what you want, but I found this on one of my NetBeans projects config:

# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
    ${javac.test.classpath}:\
    ${build.test.classes.dir}

这篇关于NetBeans-为从NetBeans启动的每个JVM设置系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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