Home

JSP and Beyond

a pragmatic primer on building web-based solutions with Java technologies


Apache Ant

Bugs are generally thought of as a bad thing, especially in relation to software development. This being said, Ant has rightfully made quite a name for itself in the development world. It is a powerful “build” and deployment automation tool that can be configured using XML. You can think of the tool as being a very powerful, highly configurable batch file.

In any medium- or large-scale software project it is not unusual to spend a lot of time preparing your files to get sent to a server where end users will use or test your application. Ant excels at providing repeatable build processes, especially for more complex deployments, when many files may need to be compiled, adjusted, directories created, moved, sent over FTP, etc. Here is an example of an Ant file from the Apache Ant help file that demonstrates how the XML file guides the build process.

<project name=”MyProject” default=”dist” basedir=”.”>
<description>
simple example build file
</description>
<!– set global properties for this build –>
<property name=”src” location=”src”/>
<property name=”build” location=”build”/>
<property name=”dist” location=”dist”/>

<target name=”init”>
<!– Create the time stamp –>
<tstamp/>
<!– Create the build directory structure used by compile –>
<mkdir dir=”${build}”/>
</target>

<target name=”compile” depends=”init”
description=”compile the source ” >
<!– Compile the java code from ${src} into ${build} –>
<javac srcdir=”${src}” destdir=”${build}”/>
</target>

<target name=”dist” depends=”compile”
description=”generate the distribution” >
<!– Create the distribution directory –>
<mkdir dir=”${dist}/lib”/>

<!– Put everything in ${build} into the MyProject-${DSTAMP}.jar file –>
<jar jarfile=”${dist}/lib/MyProject-${DSTAMP}.jar” basedir=”${build}”/>
</target>

<target name=”clean”
description=”clean up” >
<!– Delete the ${build} and ${dist} directory trees –>
<delete dir=”${build}”/>
<delete dir=”${dist}”/>
</target>
</project>

Our purpose here is not to dive into the details of Ant, but to help you understand that it is a very powerful tool for standardizing deployments and saving time. The above sample from Apache starts to hint at how much activity can be automated with a single mouse click.

You can learn a good deal more about Ant at http://ant.apache.org/.