Apache Ant Instructions


Apache Ant  is a build tool with special support for the Java programming language but can be used for just about everything. Ant is platform-independent; it is written purely in Java. Ant is particularly good at automating complicated repetitive tasks and thus is well suited for automating standardised build processes. Ant accepts instructions in the form of XML documents thus is extensible and easy to maintain.

  1. Download and Install Apache Ant

          installation the machine that the software is being installed on. Append /path/to/jdk/lib/* to the CLASSPATH environment variable.

         The installation instructions provided with the Ant software installation download are clear enough to warrant abstaining from writing any more   

         about the installation here. Refer to /path/to/ant/docs/manual/install.html.

  1.  Basic of Ant

          Here is an example of build.xml, the building descript for ant.

# 1 	<?xml version="1.0"?> 
# 2 	<project name="test" default="compile" basedir="."> 
# 3		 <property name="src" value="."/> 
# 4		 <property name="build" value="build"/>
# 5		 <target name="init">  
# 6		        <mkdir dir="${build}"/>
# 7		  </target>
# 8		  <target name="compile" depends="init"> 
# 9		          <!-- Compile the java code -->
#10		          <javac srcdir="${src}" destdir="${build}"/> 
#11		  </target>
#12                </project>
Line 2 the root element of an Ant build xml file, the project element. Its 'default' attribute is a required attribute which specifies the default target when there is no target presented. The 'basedir' is the base directory from which any relative directories used within the Ant build file are referenced from. If this is omitted the parent directory of the build file will be used. 

Line 3-4 the property element allows the declaration of properties which are like user-definable variables available for use within an Ant build file. The name attribute specifies the name of the property and the value attribute specifies the desired value of the property. You could refer to this property later anywhere in this build file using ${...}.

Line 5-7 a target element. A target element is used as a wrapper for a sequences of actions. A target has a name, so that it can be referenced from elsewhere, either externally from the command line, or internally via the depends keyword, or through a direct call. This element has 'name', 'depends', 'if', 'unless' and 'description' attributes. The 'depends' attribute is a comma separated list of all the targets on which this target depends. The 'if' (or 'unless') attribute allows users define when some property is ( or is not) satisfied can the target be built.

Line 10 a task. The task in this example causes 'javac' to be executed, and all *.java files in the src directory are compiled, and destined classes are stored in the build directory.

For more details or advanced topics about Ant, pleas refer to the Ant documentation, which could be found in the subdirectory \path\docs directory, in which \path is the directory you install Ant. Or you could find documentations at Online Ant Manual.

  1. Using Ant and Tomcat Together

         While you are developing web applications based on Tomcat, the way you use Ant to compile projects is not different from the basic way to use

         Ant. The only thing should be notified is that there is a set of properties supported by Tomcat. You can start with the example build.xml provided

        by Tomcat to create your own. Pleas first make sure Tomcat is started, and then use http://localhost:8080/tomcat-docs/appdev/build.xml.txt to visit

        it. Follow the comments in the example build.xml, and customize it for your application.

 

 

 

 

      (This instructions mostly comes from Ashley J.S Mills, please click here for the whole version of review)

 

Go Back To TA Page  


Course Webpage | JSP | Servlet | Apache Ant | Apache Jakarta Tomcat | FAQ | Contact Us