Using Custom Ant Tasks

You can create your own Ant tasks and use them in your build scripts. There is a template Ant Projects | Custom Task which you can use as a starting point. For more details on how to write Ant tasks, see the Ant documentation. Within the IDE, code completion is available for the Ant API, and Javadoc documentation for the Ant API is mounted in the Javadoc tab (so e.g. Ctrl-F1 will search it).

The Ant module supports two styles provided by Ant: with and without an explicit classpath.

With Explicit Classpath

This is generally to be recommended. You write your tasks and then include in the build file (or wherever you like) instructions to compile them (and maybe produce a JAR of them too). To use them, include the long form of taskdef which includes a classpath. Here is a simple example:
<project name="test" default="all" basedir=".">
    <target name="init">
        <javac srcdir="tasksource" destdir="tasksource"/>
        <jar jarfile="mytasks.jar" basedir="tasksource">
            <exclude name="**/*.java"/>
        </jar>
        <taskdef name="customtask" classname="com.mycom.MyCustomTask"
                 classpath="mytasks.jar"/>
    </target>
    <target name="all" depends="init">
        <customtask someparam="val"/>
    </target>
</project>
The advantage is that no special preparation is needed to begin using the script; it is entirely self-contained. You can develop the tasks inside the IDE too if you like, and the script will compile them for you automatically.

Automatic Classpath

In this case there is no particular place, according to the script, where the custom tasks are stored. The classpath attribute is missing from the taskdef. In this case you need to add the tasks to your classpath before starting Ant on the command line.

Inside the IDE, it also works to start the IDE with the tasks in its classpath. But a much better idea is to just mount the filesystem containing the source code for your tasks in the IDE's Filesystems tab. You can use the IDE to interactively develop and compile the tasks; the Ant script will automatically look for task definitions in your filesystems every time it is run. To make this work, all you need to do is add the following subelements to your taskdef:

<classpath>
    <pathelement path="${netbeans.library.path}"/>
    <pathelement path="${netbeans.filesystems.path}"/>
</classpath>
The properties above will be expanded by the IDE to classpaths containing first all of the IDE's own libraries (including Ant, parsers, ...), and then to all of your mounted filesystems.

Optional Tasks

The Ant integration module includes Ant's optional.jar. These tasks are by and large optional, because they require special libraries not shipped with Ant (and generally not shipped with the IDE either). If you need to use some of these tasks, try downloading the extra libraries and placing the JARs in the IDE's lib/ext/ directory.

Implicit

One style is not yet supported by the module: defining tasks implicitly. Ant lets you add default task definitions to a special file that lets any script you use automatically pick up task definitions. This feature may be supported in the Ant module in the future.

Custom Tasks and the Explorer View

If you define custom tasks and then run a project using them at least once, the Ant module will recognize their XML structure and allow you to edit them in the Explorer just like standard tasks. The same goes for custom data types. More features will work as intended if you use the no-explicit-classpath option.