O'Reilly logo

Ant: The Definitive Guide by Jesse Tilly, Eric M. Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An Example: XmlLogger

The XmlLogger source code is included with every source distribution of Ant. If you wish to follow along with the code, you’ll need to download the source distribution.[44] The XmlLogger redirects the normal logging output from Ant and writes it to a file in XML markup. Its simplicity and wide availability in source form make it a good example for learning how to write build listeners.

If you’re interested in seeing how XmlLogger works, test it with your standard Ant installation. There’s no need to download the source distribution as the XmlLogger class comes with all binary distributions. Unlike the case when adding tasks, there’s no need for you to declare a listener using markup in the buildfile like <taskdef>. Instead, declare it on the command line. First, insure the class is visible to Ant. You can do this by adding it to your system’s classpath or by packaging it into a JAR and placing the JAR in ANT_HOME/lib. Then, specify the listener class as an argument to the ant command. The -listener listenerClass argument notifies the Ant engine that it must add the specified listener class to the internally managed list of build listeners. You may specify more than one listener argument, with no limit on the total number. Well, there’s almost no limit. Any command-line byte-length limitations inherent to your shell still apply. To use the XmlLogger listener, you call ant like so:

ant -listener org.apache.tools.ant.XmlLogger

Running this command and its argument ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required