You are on page 1of 21

Ant: Java’s Answer to

Make
SEng 371 Lab 5
By: Bassam Sayed
Apache Ant
—  A platform independent build tool.
—  It is designed for and written in Java. Thus it is
platform independent.

—  Most of open source Java projects uses Ant as their


build tool such as Tomcat and JDOM.

—  It is suitable for large, complex software projects.


Apache Ant (Cont.)
—  It can effectively be used to build non Java projects
such as C and C++ projects.

—  Runs in Java itself


—  Only creates one JVM, regardless of # of
compilations
—  Has direct access to javac s dependency engine
—  Extensible via new Java modules/subclassing
—  Build files are written in standard XML as opposed to a
specialty language.
Why Use Ant Instead of
make?
—  Ant is more portable
—  Ant only requires a Java VM (1.1 or higher)
—  make relies on OS specific commands to carry out it’s tasks
—  make can be used under Windows using Cygwin (a UNIX
emulator)

—  Ant targets are described in XML


—  make has a cryptic syntax
—  make relies on proper use of tabs that is easy to get wrong
—  you can’t see them

—  Ant is better for Java-specific tasks


—  faster than make since all tasks are run from a single VM
—  easier than make for some Java-specific tasks
—  such as generating javadoc, building JAR/WAR
How Ant Works?
—  Ant Commands are implemented by Java Classes
—  many are built-in
—  others come in optional JAR files
—  custom commands can be created
—  Each project using Ant will have a build file
—  typically called build.xml since Ant looks for this by
default

—  Each build file is composed of targets


—  these correspond to common activities like compiling
and running code
How Ant Works? (Cont.)
—  Each target is composed of tasks
—  executed in sequence when the target is executed
—  like make, Ant targets can have dependencies
—  for example, modified source files must be compiled
before the application can be run

—  Targets to be executed


—  can be specified on the command line when invoking
Ant
—  if none are specified then the default target is
executed
—  execution stops if an error is encountered
How Ant Works? (Cont.)
—  Each target is only executed once
—  regardless of the number of other targets that
depend on it
—  for example
—  the “test” and “deploy” targets both depend on
“compile” the “all” target depends on “test” and
“deploy” but “compile” is only executed once when “all”
is executed

—  Some tasks are only executed when they need to be


—  for example, files that have not changed since the last
time they were compiled are not recompiled
Ant Build Files
—  One build file can be used to set classpath, compile
and run your program, generate javadocs, create
jars, perform CVS commands, and much more

—  Ant build files contains the following tags:


—  Project: The name and location of your software
project.
—  Properties: Global variables.
—  Targets: Group of Tasks.
—  Tasks: Commands that Ant perform to build the
Targets.
Ant Example Build File
—  After the regular XML header we start by declaring
our project in build.xml file
<?xml version="1.0" encoding="UTF-8"?>

<project name= ProjectXYZ" default= compile" basedir=".">

<description>
Build file for ProjectXYZ (optional)
</description>

</project>
Ant Example Build File
(Cont.)
—  Next we add some properties to the XML file.

<property name="source" location=“src"/>


<property name=“classes" location=“build/classes"/>
<property name="classpath" value=“.:build/classes" />


Ant Example Build File
(Cont.)
—  Lastly we add targets and tasks that execute and
build the targets.

<target name="compile" >


<javac srcdir="${source}" destdir="${classes}"/>
<classpath>
<pathelement path="${classpath}"/>
</classpath>
</javac>
</target>
Installing Apache Ant
—  Make sure you have a Java environment installed
—  Download Ant.
http://ant.apache.org/manual/install.html#getBinary
—  Uncompress the downloaded file into a directory
—  Set environmental variables JAVA_HOME to your Java
environment, ANT_HOME to the directory you uncompressed
Ant into.
—  Add ${ANT_HOME}/bin (Unix) or %ANT_HOME%/bin
(Windows) to your PATH. For more details follow this link
http://ant.apache.org/manual/index.html#setup

—  Optionally, add any desired Antlibs. See


http://ant.apache.org/antlibs/proper.html for more details.
Ant Built-In Tasks
—  Ant includes some built-in tasks that simplifies the
build process of the targets.
—  jar: Creates JAR file from a set of files
—  java: Runs Java application
—  javac: Compile Java Source Files
—  javadoc: Generates javadoc HTML files from Java
Source files
—  mail: Sends email using SMTP
—  mkdir: creates directory
—  manifest: creates mainfest.txt file for jar files
—  And many more in Ant Manual
Ant Demo
Bugzilla: A bug tracking
system
Bugzilla Features
—  Track bugs and code changes
—  Communicate with teammates
—  Submit and review patches
—  Manage quality assurance (QA)
Bugzilla Benefits
—  Improves communication
—  Increases product quality
—  Improves customer satisfaction
—  Ensures accountability
—  Increases productivity
—  Adaptable to multiple situations
Bugzilla Requirements
—  A compatible DBMS
—  A suitable release of Perl 5
—  An assortment of Perl modules
—  A compatible web server
—  A suitable mail transfer agent or any SMTP server.
Tinderbox
—  Tinderbox is an automated system to track
compilations and tests

—  Red indicates compilation failed


—  Orange indicates compilation succeeded, but the
test-suite failed

—  Green indicates compilation and tests ran


successfully

—  Yellow indicates compilation is still in progress

You might also like