www.BrettDaniel.com

Ant Mistake

I learned something interesting about Ant while working on a class project last Friday. The following build task:

<delete>
  <fileset dir="." includes="*.class" />
</delete>

Is fundamentally different from:

<delete dir=".">
  <fileset includes="*.class" />
</delete>

Can you guess why? The former deletes the excess .class files left in the current directory after a build. The latter deletes my entire project. The project I had spent two days working on. The project that was due in six hours.

A chill passed through my body and small beads of sweat broke out on my forehead. I am sure every programmer has felt that deep sense of dread at some point in his or her career.

But wait! I still had Eclipse open. Relief washed over me as I found the files intact in the local history. I saved the source files to a directory named "rescue" and began rebuilding the project.

Rookie mistake, I know. The documentation even provides a warning. To my credit, I never willingly put class files in the root of a project (that's what the bin directory is for), but this particular time I had to use a tool that spewed class files all over the place when it was run.

I hope this post will serve as a warning to anyone who reads it.