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) {

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:


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


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


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


When you run with this configuration active, you should see


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