Debug Ant build problems with echo statements

Ant FAQ: How to use echo commands to debug Ant build scripts.

I've been moving back and forth between a ton of different computers lately -- Mac, Linux, and Windows computers -- and I had some problems with an Ant build script. This particular Ant script is complex, and I kept making mistakes, and needed a good way to debug the build process as I set up my application on these different systems.

Fortunately I looked at some echo statements I already had in the Ant script, and realized I already had the solution to the problem. I normally just echo out literal strings, like Running Install Task, but then I realized, hey, I can debug my problems if I echo out my properties and variables.

Here's a simple example of what I started doing. Right before I run my Ant clean task in the code snippet shown below I echo out several of the variables that are used in the delete commands:

<echo>=== CLEAN ===</echo>
<echo>package.dir = ${package.dir}</echo>
<echo>temp.dir = ${temp.dir}</echo>
<echo>cobertura.dir = ${cobertura.dir}</echo>
<target name="clean">
  <delete>
    <fileset dir="${package.dir}" includes="**/*"/>
    <fileset dir="${temp.dir}" includes="**/*"/>
  </delete>
  <delete dir="${cobertura.dir}" />
  <delete file="${cob.ser.file}" />
</target>

For emphasis, here is the same code segment, showing just the echo statements:

<echo>package.dir = ${package.dir}</echo>
<echo>temp.dir = ${temp.dir}</echo>
<echo>cobertura.dir = ${cobertura.dir}</echo>

As a final piece of information, I create these variables earlier in my Ant build script, using property commands something like this:

<property name="package.dir" value="target" />
<property name="temp.dir" value="temp" />