Magazine
 
Introduction to Ant

Path It specifies paths (such as a classpath) in a way that is portable between operating systems.

Let’s develop a Build.xml :

In Ant, all the command line tasks used for deploying an application are represented by simple XML elements. It accepts instructions in the form of XML documents thus it is extensible and easy to maintain. The Ant installation
comes with a JAXP-Compliant XML parser, that
means the installation of an external XML parser is not necessary.

In this section, a simple Ant example is shown below which is followed by a set of instructions that indicates how to use Ant.

Simple build process with Ant (build.xml):

<?xml version=”1.0"?>
<project name=”antCompile”
default=”deploy” basedir=”.”>
<target name=”init”>
<property name=”sourceDir”
value=”src”/ >
<property name=” classDir “
value=”build” />
<property name=”deployJSP” value=”/
web/deploy/jsp” />
</target>
<target name=”clean” depends=”init”>
<deltree dir=”${ classDir }” />
</target>
<target name=”prepare” depends=”clean”>
<mkdir dir=”${ classDir }” />
</target>
<target name=”compile”
depends=”prepare”>
<javac srcdir=”${sourceDir}” destdir=”${
classDir }” />
</target>
<target name=”deploy”
depends=”compile,init”>
<copydir src=”${jsp}”
dest=”${deployJSP}”/>
</target>
</project>

 

 

Now, let’s understand one by one each tag of
this XML file.

  1. <?xml version=”1.0"?>
    Since Ant build files are XML files so the document begins with an XML declaration that
    specifies which version of XML is in use.

<project name=”antCompile” default=”deploy” basedir=”.”>

The root element of an Ant build file is the project element that contains information about the overall project that is to be built. It has three attributes.

  • name: It defines the name of the project that can be any combination of alphanumeric characters that constitute valid XML.
  • default: It references the default target that is to be executed, and when no target is specified. Out of these three attributes default is the only required attribute.
  • basedir: It is treated as the base directory from which the relative references contained in the build file are retrieved. Each project can have only one basedir attribute.

3. <target name=”init”> or <target name=”clean” depends=”init”>

The target element is used as a wrapper for sequences of actions. It contains four attributes: name, if, unless, and depends. Ant requires the name attribute, but the other three attributes are optional.

name: The name of the target is used to reference it from elsewhere, so that it can be Introduction to Ant
Jan-08 Java Jazz Up 41 referenced from elsewhere, either externally from the command line, or internally via the depends keyword, or through a direct call.

Jan 2008 | Java Jazz Up | 40
 
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