Java Reference
In-Depth Information
much to rebuild. Rerunning your JU nit tests by hand after each build can be equally
inconvenient for the same reasons.
Ant can solve both problems. Ant is not only an essential tool for building applica-
tions but also a great way to run your JU nit tests.
9.3
Introducing and installing Ant
One reason for Ant's popularity is that it's more than a tool: Ant is a framework for
running code. In addition to using Ant to configure and launch a Java compiler, you
can use it to copy files, run JU nit test suites, and create reports.
You configure Ant through an XML document called a build file , which is named
build.xml by default. The Ant build file describes each task that you want to perform
in your project. A build file can have several targets , or entry points, so that you can
run a single target or chain several targets together. Let's look at using Ant to run tests
automatically as part of the build. If you don't have Ant installed, see the following
sidebar. For full details, consult the Ant manual ( http://ant.apache.org/manual/).
Now that you're familiar with Ant and have it installed, let's get started with
a project.
Installing Ant on Windows
To install Ant on Windows:
1 Unzip the zip distribution file to a local directory (for example, C:\Ant). In this
directory, Unzip creates a subdirectory for the Ant distribution, for example,
C:\Ant\apache-ant-1.8.0.
2 Add an ANT_HOME variable to your environment with this directory as the value,
for example:
Variable name: ANT_HOME
Variable value: C:\Ant\apache-ant-1.8.0
3 Edit your PATH environment variable to include the %ANT_HOME%\bin folder:
Variable name: PATH
Variable value: %ANT_HOME%\bin;%PATH%
4 We recommend that you specify the location of your Java Development Kit
(JDK) as the JAVA_HOME environment variable:
Variable name: JAVA_HOME
Variable value: C:\jdk1.6.0_14
This value, like the others, may vary depending on where you installed the JDK
on your system.
5 To enable Ant's JUnit task, copy the file junit.jar to the %ANT_HOME%\lib
folder. Ant will add the JAR file to the classpath for your build. We look at other
options later.
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search