Magazine
 
Introduction to Ant

depends: depends contains the list of the targets that must be executed prior to executing this target. For example in the second line, the clean task will not start until the init task has completed.

if: This is a useful attribute which allows one to add a conditional attribute to a target based on the value of a property. The if will execute when the property value is set.

unless: This is the converse of if. The targets’
contents will be executed if the value is not set
(to any value).

The init target from the simple example contains three lines of property commands as shown here:

<property name=”sourceDir” value=”src”/ >
<property name=” classDir “ value=”build” />
<property name=”deployJSP” value=”/
web/deploy/jsp” />

The property element allows the declaration
of commonly used directories or files that are
like user-definable variables available for use
within an Ant build file. The name attribute
specifies the name of the directory or file as a
logically and the value attribute specifies the
desired value of the property.

For example, in the markup shown above “sourceDir” has been assigned the value “src”.

4. Then, you can have the reference of these specified variables later in the Ant file to obtain the value for these tags using ${dir name}.
For example two other commands present in
the above buildfile are:

<deltree dir=”${ classDir }” />
<mkdir dir=”${ classDir }” />

The first command removes the entire tree contained under the classDir. The second command makes a directory again using the

 

mkdir element.
5. <target name=”compile” depends=”prepare”>
<javac srcdir=”${sourceDir}” destdir=”${
classDir }”/>
</target>

This section of a build file covers the compilation process. The javac element, as used above is a command. It requires a source directory (the input location of the .java files) and a destination directory (the output location of the .classes file). It is important to note that all directories
must either exist to run the ant command or be created using the mkdir command. The example above will compile all the .java files in the directory specified by the src property and placing the resultant .class files in the directory specified by the build property.

6. <target name=”deploy” depends=”compile,init”>
<copydir src=”${jsp}” dest=”${deployJSP}”/ >
</target>

Once the compile task has been complete, at last the deploy task will perform the copy operation to copy all JSP files from the source directory to a deployment directory using the copydir command.

     
 Jan 2008 | Java Jazz Up | 41
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF