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.

Warning

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">
    <sound>
        <success source="${user.home}/sounds/success.wav"/>
        <fail source="${user.home}/sounds/noway.wav"/>
    </sound>
</target>

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

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

Attribute

Description

Required

Default

source

Specifies the name of a sound file

Yes

 

loops

Specifies the number of times to play the sound file

No

0

duration

Specifies the ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.