1

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

Community
  • 1
  • 1
Bart Weber
  • 1,136
  • 4
  • 15
  • 32

1 Answers1

0

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}
Jean Waghetti
  • 4,711
  • 1
  • 18
  • 28
  • Thanks for answering. I couldn't find the nbpoject folder. I found out that this folder is available when a standard Java application is created with NetBeans. When a Java Application with Maven is created there's no nbproject folder available and so there's no project.properties file. Or is there but in a different folder? – Bart Weber Sep 10 '13 at 18:45
  • I use ant scripts, written by myself. And change the name of the NetBeans ant script in the configuration file I mentioned. I created a maven project, but there isn't NetBeans configuration in it. It seems NetBeans relies only in Maven for a Maven project. Maybe this will help: http://stackoverflow.com/questions/7579776/how-to-set-jvm-parameters-for-junit-unit-tests – Jean Waghetti Sep 10 '13 at 19:47
  • I found out that in the project properties window it is possible to set some execution arguments for executing a Test file: File > Project Properties > Actions > Actions > Test file. Then you can type in the field Set Properties something like: `exec.args=-Dlog4j.configuration=file:/c:/log4j/log4j.properties`. But still, this is so specific, I would like to have a field to set global System Properties. The strange thing is that NetBeans uses the Maven Global Execution Options - mentioned in my question - for some of the actions. Why not all of them? – Bart Weber Sep 11 '13 at 09:15