concept other task in category ant

appears as: other tasks, other tasks
Ant in Action

This is an excerpt from Manning's book Ant in Action.

To create the JAR file, we’re going to use an Ant task called, appropriately, <jar>. We’ve dedicated chapter 5 to this and the other tasks used in the packaging process. For this introductory tour of Ant, we use the task in its simplest form, when it can be configured to make a named JAR file out of a directory tree:

The trouble with this approach is that it assumes that the type of the task <java> will always be that of the Java task, org.apache.tools.ant.tasks.Java. The moment someone uses <presetdef> to redefine the <java> task, (perhaps to give it a new default), its type changes, breaking code inside other tasks. Ant itself had to undergo a major cleanup once this problem was noticed. Current code just creates an instance and then configures it.

17.8. Delegating to other tasks

This chapter has shown how to write and test Ant tasks. It has one big topic left to cover: how to delegate work to other tasks and Java programs, and how to set up the classpaths to do so. Many of Ant’s tasks are just simple wrappers around Java or native programs. Most of the SCM tasks simply set up the command line arguments for the native command-line tools. Many of the JDK-related tasks invoke the program bundled in the JDK as a native program (<genkey> and <signjar>) or by directly invoking the Java entry point (<javac> and <rmic>). There’s a lot of duplicate work going on here, so obviously some shared classes do the heavy lifting. What are these classes? They are the classes behind <exec> and <java> tasks, tasks we’ve been using throughout the book.

Many of Ant’s tasks delegate work to other tasks. Every Ant task that’s implemented in Java can be created in another Ant task simply by calling its constructor. It can then be configured by using its Java API—the setters and other methods designed for Ant to call by introspection.