FeaturesPluginsDocs & SupportCommunityPartners

Importing Existing Applications into NetBeans IDE — Concepts


Project Types Compared

Standard Free-Form

Uses a NetBeans-generated Ant build script to build, run, and debug your application.

 

Uses targets in an existing Ant script to run, compile, clean, test, and debug your application. If the Ant script does not contain targets for some of these functions, the functions are unavailable. You can write targets to implement these functions, either in your Ant script or in a secondary Ant script.

Each project can only contain one source folder and, for J2SE projects, one test folder. To use multiple source folders, create a separate project for each source folder and create dependencies between the projects.

Can have any number of source folders. Source folders can be added and removed after project creation. You can also create dependencies to other NetBeans projects.

The build process is customized by setting basic options in the Project Properties dialog box or by overwriting targets in the NetBeans-generated Ant script.

All compilation and runtime options are set in the Ant build script. Your project settings mimic the contents and classpath relationships that are declared in your Ant script in order to enable code completion, refactoring, and error highlighting.

The IDE builds one JAR file (for J2SE projects) or WAR file (for web projects) for the entire project.

The IDE builds as many build products as are specified in the project's Ant script.

The IDE contains the following standard project templates:

  • Java Application
  • Java Library
  • Web Application
  • Java Project with Existing Sources
  • Web Project with Existing Sources

The IDE contains the following free-form project templates:

  • Java Project with Existing Ant Script
  • Web Project with Existing Ant Script

Source Folders

When you add a folder containing source code, you must add the folder that contains the highest folder in your package tree — for example, for the com.jcardshark.blackjack.ui package, you add the folder that contains the com folder.

Standard.

You can only have one source folder and one JUnit test folder in each project. To work with multiple source folders, create a project for each source folder and put the projects on each other's classpath as necessary.

Free-Form.

You can have multiple source folders and define complex classpath relationships between folders. The source folders can exist anywhere on disk and can be added and removed after the project is created.


Project Folder

The project folder contains the Ant script and properties files that control how your project is built and run.

Standard.

The project folder contains two Ant scripts:

  • nbproject/build-impl.xml. Contains the instructions for handling your project. This file is generated by the IDE and should not be edited.
  • build.xml. Imports targets from build-impl.xml. You can edit this file to override existing targets or create new targets.

The project folder also contains the output folder for compiled classes, JAR files (for J2SE projects) or WAR files (for web projects) files, and Javadoc.

Free-Form.

When you specify the Location in the free-form project, this location does not necessarily need to be the folder that contains the Ant script. For example, if you have all of your source package folders organized into one folder, you could set that folder as the project location even if it does not contain the Ant build script. The location of the output folders depends on how your Ant script is configured.


Web Module Root

The web module root is the top-level folder of a web application. It is where your JSP pages, client-side classes and archives, and static web resources, such as images, are stored. The illustration below shows the source structure of a typical web application.


Main Project

When your application is organized into several projects, the main project serves as the entry point to the application. Usually, the main project contains the main class that starts the application. Many menu commands such as Run and Build have keyboard shortcuts to the main project. You can also access all commands for individual projects by right-clicking their project nodes in the Projects window.

To make a project the main project, right-click the project's node in the Projects window and choose Set as Main Project.


Linking Commands to Ant Targets

Free-form projects rely on your Ant script to provide targets for all IDE actions, including:

  • Building
  • Cleaning
  • Compiling the project
  • Compiling a single file
  • Compiling a JavaServer Pages file
  • Running the project
  • Running a single file
  • Generating Javadoc
  • Running JUnit tests
  • Running the project in the debugger
  • Running a single file in the debugger
  • Fixing and continuing
  • Redeploying a web project

If your Ant script does not contain targets for any of these actions, the commands are disabled in the IDE. You can easily write targets for these commands and then associate them with the commands in the project's Project Properties dialog box.

If you cannot edit your Ant script to include the new targets, you can write a secondary Ant script containing the targets. For more information, see Advanced Free-Form Project Configuration.


Project Window and Files Window

The Projects window shows a package-based view of your projects. You can right-click the project node to run commands on the project. You can configure project options by right-clicking the project node and choosing Properties.

The Files window shows you the physical layout of your project files on disk. The project folder and each of your source folders are displayed for each of your projects. The nbproject folder contains project metadata for your project.


Setting the Classpath


Standard.

When you add classes to a project's classpath, the IDE makes these classes available for code completion and refactoring. You can add the following types of classpath elements to a project:

  • JAR file. A packaged library of compiled Java classes for J2SE projects only.
  • WAR file. A packaged library of compiled web classes for web projects only.
  • Library. A collection of compiled classes (JAR/WAR file), source code for debugging, and Javadoc. You can create a library by choosing Tools > Library Manager from the main window.
  • Project. The build output (JAR/WAR file), source code for debugging, and Javadoc from another NetBeans IDE project. When you add a required project to a project, all of the JAR/WAR files for both projects are built when you build the main project. (In the J2SE example, building BlackJackUI also builds the required project BlackJackLib.)

Free-Form.

Your Ant script must explicitly handle the classpath elements for compilation and execution. The classpath settings that you enter when creating the project are used to provide code completion, error highlighting, and refactoring for your project. These classpath settings must match the classpath definition in your Ant script. You can set one classpath for the entire project or set the classpath for each individual source folder in your project. To declare the classpath for an existing free-form project, right-click the project node in the Projects window and choose Properties. Then click Classpath and set the classpath for each source root.


Setting the Context Path

The context provides a way to distinguish resources in one web application from resources in others that are deployed on the same server instance.

The context of an application determines the URL namespace of the contents of the web application. When a web application's context property value is set, you access the web module at http://hostname:port/context/servlet_or_jsp. For example, with the property value set to /HelloWeb, you access the web application at http://hostname:port/HelloWeb/index.jsp.


Bookmark this page

del.icio.us furl simpy slashdot technorati digg
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Open ESB - The Open Enterprise Service Bus Powered by