Apache NetBeans Wiki Index

Note: These pages are being reviewed.

Run Configurations for Java SE Projects

Demo Script

Prerequisites:

  1. NetBeans 6.0 (tested against 20070419 ~ M9)

    1. JDK 6.0u1

    2. Any supported OS (tested on Ubuntu)

Preparation:

  1. Create a Java application.

    1. Add to the main method:

  System.out.println("First main class.");
  1. Add a new Java main class. Add to its main method:

System.out.println("Second main class.");
  1. Click Run (F6). You should see

run:
First main class.
BUILD SUCCESSFUL

Demo steps:

  1. From the <default> combo in the toolbar, select Customize…​.

    1. Click New…​ (configuration).

    2. Enter name second and click OK.

    3. Click Browse…​ (for main class).

    4. Pick the second class and click Select Main Class.

    5. Click OK to close the Properties dialog.

    6. Click Run; you should see

run:
Second main class.
BUILD SUCCESSFUL
  1. Choose <default> again in the combo and click Run; you should see the first main class again.

    1. Right-click the project and choose Properties.

    2. Under Run, switch to second configuration.

    3. Add -showversion to VM Options. Note that the field’s label becomes boldfaced.

    4. Click OK and Run; you should see

run:
java version "1.6.0_01"
JavaTM SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpotTM Server VM (build 1.6.0_01-b06, mixed mode)

Second main class.
BUILD SUCCESSFUL

Optional material

Question: Can I control other things besides Run options?

Answer: You can, though for at least for 6.0 this is not supported through the GUI. For example, go to the Files tab and open nbproject/configs/second.properties. Add:

build.compiler=extJavac
javac.compilerargs=-J-showversion

With the configuration set to second, press Clean and Build Main Project (S-F11). You should see

Compiling 2 source files to /tmp/JavaApplication1/build/classes
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

compile:

Generally, anything normally set in project.properties can be overridden on a per-configuration basis. The Properties dialog outside the Run panel will only show the contents of project.properties, however.

The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.

This page was exported from http://wiki.netbeans.org/RunConfigurations49636 , that was last modified by NetBeans user Jglick on 2010-02-19T17:02:01Z.

This document was automatically converted to the AsciiDoc format on 2020-03-12, and needs to be reviewed.