Revision as of 21:16, 6 November 2009 by Admin (Talk | contribs)

How to Work with Ant in the NetBeans IDE </div>

By: Daria Titova, with contributions of Mikhail Kondratyev, Jesse Glick

August 2007

In this tutorial, you will convert Ant to a NetBeans project and learn how to build and perform test-runs of Ant in the NetBeans IDE. </span>



Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles. Ant is one of the most popular build tools in the Java world. This tutorial shows you how to use the NetBeans IDE for Ant development.

The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications. In this tutorial, you learn how to convert the Ant open-source project to a NetBeans project to develop, build, and test Ant within the Netbeans IDE.

For more information on how to work with the NetBeans IDE, see the Support and Docs page.

Software needed

Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0.
Since NetBeans 6.0 is under development now, use NetBeans IDE 6.0 Beta 1 available from NetBeans IDE 6.0 Beta 1 Download or check the latest working version at

Notations used in this documentation

  • <NETBEANS_HOME> - the NetBeans IDE installation directory
  • <USER_HOME> - the user's home directory. Example: "C:\Documents and Settings\user_home"
  • <ant_src_root> - directory with the Ant sources.


Here we explain how to easily convert Ant project into a NetBeans project

Converting Ant to a NetBeans Project

To download the Ant sources:

1. Download the Ant source code from or check it out from the repository using Subversion: 'svn co'.
This tutorial uses the source base obtained by svn checkout. To work with the sources from source distribution, follow the same steps but copy junit-3.8.2.jar to the <ant_src_root>/lib/optional directory.

To create the Ant NetBeans Project:

This tutorial uses the Ant NetBeans project created by Jesse Glick, an Apache Ant committer who works with Ant in the NetBeans IDE. Jesse's idea was to use wrap.xml in addition to existing Ant's build.xml. The wrap.xml file wraps every target of original build.xml using a special macro which adds a specific configuration logic. Explore wrap.xml in the attached file for more details.

1. Download the attached file, and extract it into the <ant_src_root> directory. Now you see nbproject directory under the <ant_src_root> directory. There are 3 files under <ant_src_root>/nbproject:, project.xml, and wrap.xml.

2. Modify the file to set up project.dir, jdk12.home, jdk14.home, and jdk16.home properties (use absolute paths):

jdk12.home=<path_to_jdk12> # or <path_to_jdk15>
jdk14.home=<path_to_jdk14> # or <path_to_jdk15>
jdk16.home=<path_to_jdk16> # or <path_to_jdk15>
run.args=-f <path_to_sample_buildfile>

In this case the file appear as follows:

jdk12.home=C:/Program Files/Java/jdk1.5.0_12/
jdk14.home=C:/Program Files/Java/jdk1.5.0_12/
jdk16.home=C:/Program Files/Java/jdk1.5.0_12/
run.args=-f <path_to_sample_buildfile>

3. From the main menu, choose File > Open Project.
In the Open Project wizard specify <ant_src_root>.


Click Open Project.

The Projects window contains a project node for the Ant you have just created. Now you can develop Ant within the NetBeans IDE.

The project will be marked with a red exclamation mark. This means there are some classes and/or jars which NetBeans does not know the path to. If you want to eliminate red exclamation marks, specify the path to classes in the NetBeans IDE. This tutorial does not cover the details of eliminating exclamation marks because they do not break project building, testing, and running.

Building the Ant Project

1. In the Projects window, right-click the Ant project node and choose Build Project or Clean and Build Project from the pop-up menu. If Ant Projects is set as main, you can press the Build Main Project in the toolbar Image:toolbar-build_NetbeansedAnt.png or press F11.


The Ant .jar file is built and you see the "BUILD SUCCESSFUL" message in the Output window.


Testing the Ant Project

To perform testing of the Ant project, do the following:

1. In the Projects window, right-click the Ant project node and choose Test from the pop-up menu, or press Alt+F6.


A test run of the Ant project is performed and you see test results in the JUnit Test Result and Output windows.


Running the Ant Project

Before running the Ant project, we must create a sample buildfile to run the Ant with this buildfile.

1. Create a sample buildfile. This tutorial uses the following sample.xml as a sample buildfile:

<?xml version="1.0"?>
<project name="sample-ant" default="main" basedir=".">
    <target name="main">
        <echo>Running sample script...</echo>

2. Modify the file to set up the run.args property pointing to newly created sample buildfile (use an absolute path).


Save the file.

3. In the Projects window, right-click the Ant project node and choose Run from the pop-up menu. If Ant Projects is set as main, you can press the Run Main Project in the toolbar Image:toolbar-run_NetbeansedAnt.png or press F6.


The IDE runs Ant with the sample buildfile and you see information about Ant executing build script in the Output window.


Profiling the Ant Project

Before profiling the Ant project, you must create a sample buildfile to perform Ant profiling. See steps 1 and 2 in the Running the Ant Project section.

1. In the Projects window, right-click the Ant project node and choose Profile Project from the pop-up menu. If the Ant project is set as main, you can press the Profile Main Project in the toolbar Image:toolbar-profile_NetbeansedAnt.png.


2. In the Profile Ant window, accept the default "CPU > Analyze Performance" option and click Run.


3. In the Select Task for Profiling window, select the profile task from the checkbox, and click OK.


The Profiler tab opens in the Netbeans IDE and the Profiler collects information about running the Ant with the sample buildfile.



In this tutorial, you learned how to start Ant development in the NetBeans IDE. You have completed the following exercises:

  • Convert Ant into a Netbeans Project.
  • Build Ant in the NetBeans IDE.
  • Test Ant in the NetBeans IDE.
  • Run Ant with Sample Buildfile in the NetBeans IDE.
  • Profile Ant in the NetBeans IDE.

See Also


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