Java Reference
In-Depth Information
How It Works
Apache Ant (or simply Ant) is a program that allows you to script your project's build
and unit testing. By configuring Ant, you can build, test, and deploy your application
using the command-line. (In turn, it can be scheduled to be run automatically by the
operating system.) Ant can automatically run unit tests and report on the result of these
tests. These results can then be analyzed after each run to pinpoint changes in behavior.
Due to Ant's complexity, it has a large learning curve, but it allows for a lot of flex-
ibility on compiling, building, and weaving code. By using Ant, it is possible to
achieve the utmost configuration on how your project is built.
Note Visit http://ant.apache.org/manual/index.html for a more in-
depth tutorial of Ant.
The build.xml file contains instructions on how to compile your project, which
class path to use, and what unit tests to run. Each build.xml contains a <pro-
ject> tag that encapsulates the steps to build the project. Within each <project>
there are targets, which are “steps” in the build process. A <target> can depend on
other targets, allowing you to establish dependencies in your project (in this recipe's
example, the target “test” depends on the target “build,” meaning that to run the test
target, Ant will first run the build target).
Each target contains tasks. These tasks are extensible, and there is a core set of
tasks that you can use out of the box. The <javac> task will compile a set of Java files
specified within the src attribute and write the output to the dest attribute. As part of
the <javac> task, you can specify which class path to use. In this example, the class
path is specified by referring to a previously defined path, known as build.path .
Ant provides ample support for creating class paths. In this recipe, the class path is
defined as any file that has the .jar extension located in the dep folder.
The other task in the build target is <junit> . This task will find a unit test speci-
fied in its task and run it. The unit tests are defined within the <batchtest> prop-
erty. By using the <fileset> property, it is possible to tell JUnit to find any file that
has the word Test in its name and ends with the .java extension. Once JUnit runs
each test, it will write out a summary to the console and write a report on the results of
the unit tests to the reports.tests folder.
Search WWH ::




Custom Search