Advanced Compilation and Execution Support
When you double-click on a target node, it always simply runs that target - enough
said. For the whole Ant script, though, you have more options for how to use the
IDE's compilation and execution systems smoothly with Ant. These options are based
on the IDE's standard device of compiler types and execution types.
Execution of Ant Scripts
By default, double-clicking an Ant script node (or selecting Execute is the
same) will just run its default target, as you might expect. Most of the time this
is what you want, but you may (for example) wish to set an Ant build script as your
project main class (right click and Tools | Set As Project
Main Class), and the default target may be suited to building a project, but when
you Project | Execute Project you may prefer to be running a different
target suited to deployment.
So, just select Ant Script Execution from Project |
Settings (or as a shortcut, select the Executor from the Property Sheet
for your Ant script and hit ...). You can modify the Target
property: if left blank, it will run the script's current default target; or you
can type in a specific target name. You may even specify several target names
(separated by spaces or commas) and all of them will be run.
As with services in the IDE in general (consult the NetBeans online help system
for more details), you can configure multiple types of Ant execution at once, setting
different execution types to different Ant scripts, and so on.
Note that the IDE by default tries to compile things before executing
them. This applies to Ant scripts, too, though it is not really what you want,
since normally an Ant target will specify all its own dependencies already.
For this reason, by default compiling an Ant script does nothing
(it is set to (do not compile)). You may also
set Tools | Options | Execution Settings |
Run Compilation to False and make scripts compilable.
Compilation of Ant Scripts
Similarly to execution, Ant scripts function in the IDE's compilation system, so
you will notice that the Build menu and toolbar is active when scripts are
selected. As mentioned above, Ant scripts by default are set to not be compilable,
so you should change this if you wish to use compilation.
If your Ant script is in your project tab in the Explorer
(to add it, right-click and Tools | Add To Project),
then Project | Compile Project will run your script.
If it is in some arbitrary folder, selecting Compile on that folder
will run it too (besides compiling anything in the folder according to the IDE's style).
You can configure the targets much as for execution types; there are separate targets
for compile (default incremental compilation), build (from scratch), and clean (remove
all build products leaving only source).
Compilation of Other Files Using Ant
You may wish to use Ant for all or much of your compilation in the IDE, replacing
the IDE's built-in compilation support (for Java sources, for example). You can do
so with this module. There is a special compiler type called
Indirect Ant Compilation, which can be applied to arbitrary files
to make them be built with Ant instead of the IDE's normal method. For example,
if you select a Java source and change its Compiler property to this compiler
type, compiling it will actually run the Ant script associated with it.
(To change the property for many files, select them all at once and change it in
one swoop; or to change the default for all Java sources, see Project |
Settings | Java Sources | Default Compiler.)
As with simple Ant compilation, you can select the targets to run in the case
of incremental compilation, building from scratch, and cleaning.
If a number of files are "compiled" at once using the indirect compiler, or
if this is mixed with the direct script compiler, not to worry - the IDE will
not run the same target more than once. Remember that if you have (for example)
a compile
target in your script, and you set the indirect compiler to
run this target, "compiling" one source really compiles any sources in the fileset
which are out of date - that is, the IDE simply asks Ant to run that target, and
Ant does not know specifically what files it should be compiling. In the future
there may be more control possible here.
By default the Ant script to run is located using Ant's normal -find search algorithm,
going up directories from the source file until a build.xml is found.
If you would like to
select a particular script to use for an indirect compiler (it need not be anywhere
near the sources), change the Script property on the indirect compiler accordingly.
By default it is blank, meaning to search for the script every time; you can
type in a full file path to a build script, or click ... to browse to
a build script located in the IDE's Filesystems.