|
4.2. Preparing to DeployAnt 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.
4.2.1. Deleting Existing FilesWhen 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 bin directory OK?" validargs="y,n" addproperty="do.delete" /> <condition property="do.abort"> <equals arg1="n" arg2="${do.delete}"/> </condition> <fail if="do.abort">Build aborted.</fail> <delete dir="${output}" /> <mkdir dir="${output}" /> </target> <target name="compile"> <javac srcdir="${src}" destdir="${output}" /> </target> <target name="compress"> <jar destfile="${output}/Project.jar" basedir="${output}" includes="*.class" /> </target> </project>
You can see the attributes of this task in Table 4-9.
The delete task can contain nested fileset elements.
4.2.2. Creating New DirectoriesWant to create the directory structure for local or network deployment? Use mkdir. This one's so important that you've seen it in use since Chapter 1. And it's easy to use with only one attribute, as you can see in Table 4-10.
Want to create a directory? Just do it: <mkdir dir="${dist}"/>
|
|