By default, the IDE ignores your environment's CLASSPATH variable whenever it runs Ant. This setting is defined by the Properties setting in Ant Settings, which sets the build.sysclasspath property to ignore. For your build script to use customs tasks, you must add the tasks to Ant's classpath in the IDE.
You can add custom tasks to Ant's classpath within the IDE by:
Using an explicit classpath is the recommended method, as it ensures that your build scripts will be fully portable. You can write your tasks and include instructions to compile them and produce a JAR file in the build file. To use these tasks, include the long form of taskdef, which includes a classpath. Here is a simple of such a task.
The advantage of this method is that no special preparation is needed to begin using the script. The script is entirely self-contained and portable. This method also makes it easier to develop your tasks within the IDE, as the script compiles them for you automatically.
To make the your build scripts even more robust, use a property instead of a hard-coded location to specify the classpath to your tasks. You can store the property in the build script itself or in a separate ant.properties file. You can then change the classpath setting throughout your script by simply changing the value of the specified property.
If you do not plan to use your build script outside of the IDE, you can mount the filesystem containing the source code for your tasks in the IDE's Filesystems tab. In your build script, add the following subelements to your taskdef:
<classpath> <pathelement path="${netbeans.library.path}"/> <pathelement path="${netbeans.filesystems.path}"/> </classpath>You do not need to provide values for {netbeans.library.path} and {netbeans.filesystems.path}. These properties are global Ant properties which the IDE expands to classpaths containing the IDE's own libraries (including Ant, parsers, and other libraries) and all of your mounted filesystems.The Ant script automatically looks for tasks definitions in your filesystems every time it runs.
If you cannot declare a classpath in your build script, or you are using third-party
build scripts which you cannot alter, you can add the tasks to your install_directory/modules/patches/org-apache-tools-ant-module/
directory. Then choose Tools Options,
expand the Building node, and select Ant Settings. Then click the ellipsis (...)
button in the Properties setting and delete build.sysclasspath=ignore.
All of the libraries in this directory are picked up by Ant when you run a build
script.
Note that this method can cause problems with executing your Ant scripts outside of the IDE. When you delete build.sysclasspath=ignore, everything in the IDE's classpath, including the IDE APIs, XML parsers, and so forth, is quietly added to the Ant classpath. You could therefore unknowingly make your Ant script dependent on one of these additional libraries and thereby make it not run outside of the IDE.
![]() |
By default, the Ant binary that the IDE uses is
located in your IDE install directory. If you download an experimental version
of the IDE's Ant module from the Update Center, however, the IDE places
the new Ant binary in your user directory instead.
The binaries for your custom tasks must always be placed in the correct directory relative to the Ant binary that you are using. If your Ant binary is located in your user directory, you have to put your custom task binaries in the modules/patches/org-apache-tools-ant-module/ directory of your user directory. |
See Also | |
---|---|
Creating a Custom Ant Task Optional Ant Tasks Configuring Ant Settings Creating an Ant Project |