Article:
  Writing Ant Tasks
Subject:   Feedback
Date:   2004-06-04 02:05:08
From:   erikhatcher
A couple of comments - in your first example, you do not even need to extend Task or import BuildException - you never throw it or use the Task infrastracture. Simply a "public void execute()" method makes a class an Ant task.


I find it comical that you used javac and jar at the command-line to build your Ant task JAR. You should have used Ant's javac and jar and shown how to build and use the custom task all in one shot. Interestingly, with the new scriptdef task you could have made your adder task purely as script (JavaScript for example).


And yes, you can use an Ant task as .class not in a JAR. Use the classpath capability of taskdef to set it. An even slicker method of defining tasks is through the new Antlib capability which avoids having fully qualified classnames in your build file which are subject to change.

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Michael Fitzgerald photo Feedback
    2004-06-05 22:21:11  Michael Fitzgerald | O'Reilly AuthorO'Reilly Blogger [View]

    (1) Sure, a simple execute() could do, as described in the tutorial, which I recommeded to readers. I wrote a simple task that has a parallel structure to the more complex Jing task, following the guidelines in the first six steps of "Writing Your Own Task". Are those guidelines incorrect or out of date? If so, this section of the Ant manual needs to be updated.

    (2) Ant is a nice tool, but I don't feel it is necessary to use it to build something as simple as Add.java -- one very small class with almost zero potential for continuous debugging or rebuilding.

    (3) As far as using .class files: How exactly do you do that? I tried it every which way from Tuesday with no luck. Show us! (I haven't paid any attention to Antlib yet. Thanks for pointing it out.)