Friday, September 24, 2004

Ant mapper datatype

Reading Java Development with Ant
Chapter 3 - Understanding Ant datatypes and properties

It's interesting to see that we have these mapper datatypes in Ant. They're very powerful, yet I have not seen many of the developers use them in their build file. I strongly suggest that these mappers be acknowledged, for the efficiency of the build process itself.

These mapper data can be used with the <uptodate>, <copy>, <move> and some other tasks. A good example would be matching a glob mapper with the <uptodate> task. For example, if no production code is updated, then no compilation should be performed.

<target description="compile if src not uptodate" name="compile">
  <condition property="src.uptodate">
      <srcfiles dir="{src.dir}" includes="**/*.java">
      <mapper type="">glob" from="*.java"
  <javac srcdir="{src.dir}">
    <classpath refid="classpath.default">

It is a very simplified version, but the purpose is to have a conditional step in the build process, e.g. no compilation should be performed if the class file is already updated, by comparing each java source code's timestamp against the corresponding (as mapped by the glob mapper) class' timestamp.

This book offers a lot of enhancement to the way we use Ant. I hope I can get a chance to read through the rest of the book.

Further Reading:
Java Development with Ant

1 comment:

  1. Helpful post, thanks. I'm just starting to look at mappers and this blog is one of the first things I've found that clarifies how they can be used.