Running a Project in the IDE


Once you have set up your project, created your source files, and set up any necessary dependencies, you can run your project in the IDE by choosing Run | Run Main Project (F6).

By default, when you run a general Java project in the IDE, the following occurs:

  • All modified files in the project are saved.

  • Any uncompiled files (or files that have been modified since they were last compiled) under the Source Packages node are compiled.

  • A JAR file with your classes and other resources is created (or updated).

  • Any projects that the main project depends on are built. (In fact, these projects are built first.)

  • The project is run inside of the IDE. For general Java projects, the IDE uses the designated main class as the entry point.

When you build your project, output on the progress of the Ant script is printed to the Output window.

Setting or Changing the Project Main Class

To run a general Java project, you have to have an executable class designated as the entry point. You can designate the main class:

  • In the New Project wizard when creating your project from the Java Application project template.

  • In the project's Project Properties dialog box. (In the Projects window, right-click the project's node and choose Properties. Then select the Run node and fill in the Main Class field with the fully qualified name of the main class, without the .java extension.)

If you try to run a project that has no main class set, you will be prompted to choose one from a list of executable classes found within the project's source packages. If the class that you want to use as the main class is not among the project's sources (for example, if it is in a subproject or another JAR on your classpath), you can set that class in the Project Properties dialog box as detailed in the procedure above.


Setting Runtime Arguments

If you need to pass arguments to the main class when you are running your project, you can specify those arguments through the Project Properties dialog box:

  1. Right-click the project's node in the Projects window and choose Properties.

  2. Select the Run node and add the arguments as a space-separated list in the Arguments field.

Setting Java Virtual Machine Arguments

If you need to pass arguments to the Java virtual machine that is spawned to run the project in, you can do so through the Project Properties dialog box:

  1. Right-click the project's node in the Projects window and choose Properties.

  2. Select the Run node and add the arguments as a space-separated list in the VM Options field.

Setting the Runtime Classpath

By default, the classpath for running the project inherits the compilation classpath. If you need to alter the classpath just for runtime, you can make adjustments in the Running Project section of the project's Project Properties dialog box:

  1. Right-click the project's node in the Projects window and choose Properties.

  2. Select the Libraries node.

  3. In the tabbed panel on the right side of the Project Properties dialog box, click the Run tab.

  4. Use the Add Project (for other IDE projects), Add Library (for collections of JARs, sources, and Javadoc that you have designated in the Library Manager), or Add JAR/Folder buttons to make additions to your classpath.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net