Preparing to Deploy
Ant supports several tasks for setting up a deployment
environment, such as delete and
mkdir. Both these tasks can be used
locally or on a network to set up the directory structure you need to
deploy applications.
Tip
If you want to create and delete directories remotely, take a
look at the ftp task, coming up
later in this chapter.
Deleting Existing Files
When deploying, delete is great to clean up a previous
installation or to clean deployment directories before installing.
This task deletes a single file, a directory and all its files and
subdirectories, or a set of files specified by one or more
FileSets.
Using this task, you can delete a single file:
<delete file="/lib/Project.jar"/>
Or you can delete an entire directory, including all files and subdirectories:
<delete dir="${dist}"/>You can use filesets:
<delete includeEmptyDirs="true">
<fileset dir="${dist}"/>
</delete>You've seen delete at work in
various places throughout the book, as in the build file in the
input folder for Chapter 3s code (repeated in Example 4-2), where the user is
asked for confirmation before deleting anything.
Example 4-2. Using the delete task (ch03/input/build.xml)
<?xml version="1.0" ?> <project default="main"> <property name="message" value="Building the .jar file." /> <property name="src" location="source" /> <property name="output" location="bin" /> <target name="main" depends="init, compile, compress"> <echo> ${message} </echo> </target> <target name="init"> <input message="Deleting ...