3. Getting Started (ANT)

This section introduces EMMA ANT tasks. It starts with an example of how to run an application from ANT so that coverage instrumentation is performed on-the-fly, as the classes are loaded by the JVM, and then repeats the same process by breaking it into distinct instrumentation/execution/reporting steps. The ANT logic sequence will be equivalent to what was described previously, in Section 2, “Getting Started (command line)”. Additionally, the ANT build.xml files created below will have logic for enabling and disabling coverage through ANT command line.

Sample source code and ANT build files

The source code located in examples/src directory of EMMA distribution is used for all examples in this tutorial. EMMA distribution also includes two sample ANT buildfiles, build-onthefly.xml and build-offline.xml, that correspond to the two approaches to collecting coverage. Although it would have been possible to keep everything in a single file, using distinct files allows for more clarity.

3.1. Adding EMMA tasks to your ANT build

EMMA ANT tasks can be deployed in any of the many ways available for custom ANT taskdefs. This tutorial assumes that you have an EMMA distribution directory that contains both emma.jar and emma_ant.jar. The latter archive is what contains EMMA taskdefs, however, both archives need to be visible to ANT. The easiest way to accomplish this is with the following definitions in your build.xml:

  <!-- directory that contains emma.jar and emma_ant.jar: -->
  <property name="emma.dir" value="${basedir}/../lib" />

  <path id="emma.lib" >1
    <pathelement location="${emma.dir}/emma.jar" />
    <pathelement location="${emma.dir}/emma_ant.jar" />

  <taskdef resource="emma_ant.properties" classpathref="emma.lib" />


Even though this path definition can be merged into the <taskdef>, a path element with this id will come in handy later in the build.