next up previous contents index
Next: Source code integration Up: Developing with Ant Previous: Tasks Desgined for Extension   Contents   Index

Build Events

Ant is capable of generating build events as it performs the tasks necessary to build a project. Listeners can be attached to Ant to receive these events. This capability could be used, for example, to connect Ant to a GUI or to integrate Ant with an IDE.

To use build events you need to create an ant Project object. You can then call the addBuildListener method to add your listener to the project. Your listener must implement the org.apache.tools.antBuildListener interface. The listener will receive BuildEvents for the following events

Build started Build finished Target started Target finished Task started Task finished Message logged If you wish to attach a listener from the command line you may use the -listener option. For example:

ant -listener org.apache.tools.ant.XmlLogger will run Ant with a listener that generates an XML representation of the build progress. This listener is included with Ant, as is the default listener, which generates the logging to standard output.

Note: A listener must not access System.out and System.err directly since ouput on these streams is redirected by Ant's core to the build event system. Accessing these streams can cause an infinite loop in Ant. Depending on the version of Ant, this will either cause the build to terminate or the Java VM to run out of Stack space. A logger, also, may not access System.out and System.err directly. It must use the streams with which it has been configured.


next up previous contents index
Next: Source code integration Up: Developing with Ant Previous: Tasks Desgined for Extension   Contents   Index
Andrew Marlow 2003-07-08