FaqSysPropsDuringRun

How can I run/debug a program in NetBeans with certain Java system properties set to certain values?

There is no GUI support for this yet, but it is possible by editing a properties file, at least for plain Ant-based Java SE projects (untested for Java EE projects). Say you have a main class like this:

public class Main {
    public static void main(String[] args) {
        System.out.println(System.getProperty("my.var"));
    }
}

You expect the program to be invoked as e.g.

java -Dmy.var=something Main

and want to test this from the IDE.

If you are using Ant, under Files open nbproject/project.properties and add a line like this:

run-sys-prop.my.var=basic

That's it; now press F6 and you should see printed:

basic

In a similar fashion, you can also set properties that should be available during JUnit unit testing:

test-sys-prop.my.var=basic

If you are working on a team and the system property definition involves some file paths local to your machine, or for whatever other reason it does not make sense for everyone to use the same definitions, just put some or all such properties into nbproject/private/private.properties.

If you are using project configurations, you can define per-configuration system properties. Just make a new configuration, say called advanced. Now open nbproject/configs/advanced.properties and add

run-sys-prop.my.var=advanced

When you run with this configuration active, you should see

advanced

Again you can have per-user per-configuration properties, in e.g. nbproject/private/configs/advanced.properties.

See also FaqEnvVarsDuringRun.


Applies to: NetBeans 6.0 and later

Platforms: all

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo