NetBeans-SCSNI

2.3-Describe the ways in which you can change the build process for a standard project, such as configuring project properties and modifying the project's Ant build script.

Building Tasks: Quick Reference

This topic describes common tasks you can perform when building a project. For more detailed information, click the links in the right column.

 To perform this task Follow these steps
 Add a JAR file to a project's classpath.
  1.  Open the Project Properties dialog box by right-clicking the project node and choosing Properties from the Project window.
  2. Select the Libraries node in the Categories pane. Then click the Compile tab.
  3. Click Add JAR and select the JAR file in the file chooser.
Add an IDE project to a project's classpath.
  1.  Open the Project Properties dialog box by right-clicking the project node and choosing Properties from the Project window.
  2. Select the Libraries node in the Categories pane. Then click the Compile tab.
  3. Click Add Project and select the project directory for the project you want to add.
 Build a project
  1. Select the node of the project you want to build.
  2. Choose Build > Build Main Project (F11) or right-click any project in the Projects window and choose Build Project.
 Stop building a project.
  •  Choose Build > Stop Build/Run from the main menu.
 Compile a single file.
  1.  Select the node of the file you want to build.
  2. Choose Build > Compile File (F9).
 Clean a project.
  • In the Projects window, right-click the project node and choose Clean Project.
 Clean and build the main project. Select the node of the project you want to clean and build.
Choose Build > Clean and Build Main Project (Shift-F11).
 View build output.
  •  In the Files window, expand the project folder node.
  • Expand the build folder to view compiled classes.
  • Expand the dist folder to view Javadoc files and built libraries, such as JAR files and WAR files.
 Correct compilation errors.
  •  In the Output window, double-click any Java syntax error to jump to the location in the source code where the error occurred.
  • In the Output window, double-click any Ant error to open the Ant script in the target that failed.


Building a Project

When you build a project, the IDE calls the corresponding target in the project's Ant build script. The IDE compiles the source files and generates the packaged build output, such as a JAR file or WAR file. You can build the main project and all of its required projects, or build any project individually.

To build the main project and its required projects:

  • Choose Build > Build Main Project (F11).
The IDE displays the Ant output and any compilation errors in the Output window.

You can double-click any error to go to the location in the source code where the error occurred.

To build an individual project and its required projects:

  • Right-click the project's node in the Projects window and choose Build Project.
The IDE displays the Ant output and any compilation errors in the Output window.
You can double-click any error to go to the location in the source code where the error occurred.

To stop building a project:
  • Choose Build > Stop Build/Run from the main menu.
For  standard projects that have a main class is specified, the IDE automatically copies any JAR files on the project's classpath to the dist/lib folder when you build the project. The IDE also adds each of the JAR files to the Class-Path element in the application JAR's manifest.mf file. This simplifies running the application outside the IDE. For more information, see Preparing a JAR for Deployment Outside the IDE.


Building a JAR File

In standard projects , the IDE builds a JAR file from your project sources every time you run the Build command. The JAR file is generated to the dist directory of your project folder.

For standard projects that have a main class is specified, the IDE automatically copies any JAR files on the project's classpath to the dist/lib folder when you build the project. The IDE also adds each of the JAR files to the Class-Path element in the application JAR's manifest.mf file. This simplifies running the application outside the IDE. For more information, see Preparing a JAR for Deployment Outside the IDE

To change the JAR name and location:

  1. In the Files window, go to the nbproject folder in your project folder and open project.properties.
  2. Enter the full path to the JAR file in the dist.jar property.

To specify which files are added to the JAR file:

  1. Right-click the project node in the Projects window and choose Properties.
  2. Select the Packaging node in the dialog's left pane.
  3. Configure the filter and compression settings in the right pane.
 
To specify the manifest file for the JAR file:

In project.properties, type the name of the manifest file in the manifest.file property. The file name must be specified relative to the project's build.xml file.

If you are using the Java Application template, the IDE creates a manifest file for you.

To disable generation of a JAR file for a project:

  • In the Files window, open your project folder and open build.xml.
  • Override the jar target to have no contents and no dependencies. For example, add the following to build.xml:
<target name="jar" />

In  free-form projects, JAR file creation is controlled by your Ant script.


-- Wagner R. dos Santos