问题描述
是否有一种方法来设置NetBeans启动的每个JVM使用的系统属性(Win 7上的NB 7.3.1)?
在我使用log4j的所有Maven项目中,需要一个log4j.properties文件,我想通过系统属性-Dlog4j.configuration=file:/c:/log4j/log4j.properties
指向的位置我可以为Maven设置全局执行选项:工具>选项> Java> Maven>全局执行选项.但是,当我在NetBean(因此没有Maven)中运行特定的JUNIT测试类时,NetBeans将不会在全局执行选项字段中使用这些JVM系统属性.
同一问题是在Netbean中运行Maven模块中的A Main类时.要设置JVM系统属性,可以设置可以设置的项目属性:"主类"和" VM选项".但是,这些项目属性仅在从Maven模块的上下文菜单中使用"运行"命令时才使用NetBeans. (不幸的是,此菜单项没有快捷键(常规shift-f6).
我已经通过设置系统变量JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties来解决此问题.
编辑
我提出了一个问题,我遇到了同样的问题:在运行测试时如何使NetBeans使用特定的JVM参数?在我的情况下,问题是由我在(文件> Project> Project Properties> build> build> compile> Compile> Compile> Compile of Save上摇摆的保存中引起的, ).在这种情况下,Netbeans似乎不使用Maven.有关COS的更多信息: http://wiki.netbeans.org/faqcompileonsave
推荐答案
在nbproject文件夹中有一个名为project.properties的文件.在此文件中,您可以执行很多配置,而这些配置不在GUI菜单中.我不知道要在那里实现您想要的东西,但是我在我的Netbeans项目之一上找到了这一点:
# 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}
问题描述
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)?
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
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.
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)).
I have worked around this by setting a System Variable JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties.
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
推荐答案
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}