Chapter 10. Optional Tasks

A significant number of optional tasks come with Antthe full list appears in Table 1-5and you’ll see several of them in this chapter. Some of the optional tasks are specialized, but a number are useful in everyday builds. You’ve seen optional tasks like junit and ftp, and this chapter expands that coverage with a look at tasks like sound, splash, replaceregexp, and depend.

Using Sound

The sound task plays a sound-file at the end of the build according to whether the build failed or succeeded. You can specify one sound file to play, or if you specify a directory, the sound task will randomly select a sound file to play.


If you’re using Java 1.3 or later, you need the Java Media Framework on the classpath (javax.sound).

The sound task can contain success and fail elements. The success element specifies the sound you want played if the build succeeds and failures the sound if it fails. Here’s an example where the build file specifies the sounds to play depending on if the build succeeded or failed:

<target name="sounds">
        <success source="${user.home}/sounds/success.wav"/>
        <fail source="${user.home}/sounds/noway.wav"/>

These success and failure elements support the attributes you see in Table 10-1.

Table 10-1. The success and fail elements’ attributes






Specifies the name of a sound file




Specifies the number of times to play the sound file




Specifies the time ...

Get Ant: The Definitive Guide, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.