Pradeep's Blog

Google

Monday, June 05, 2006

Writing Custom Ant Task

I wanted to create an Ant task for a project (CyVis - a free software metrics collection and analysis tool for java based software) that I am working on. Writing our own Ant task is actually very simple. This blog explains how to write a very simple (something like a hello world) task that can be integrated into ant.

First write a class that extends org.apache.tools.ant.Task. Then for each attribute, write a setter method like the HelloTask class shown below.

Now compile the class and place it in the classpath or in the same dir as the Ant home directory in order to use the task. Then you can call you task as shown in the script below. Note that before you can use your task, you should use taskdef to define it.

I had placed the HelloTask class file in a jar file and placed the jar file in the Ant’s home directory. You can either do this or define a classpath to say where it’s placed. Running this Ant script would print out some thing like this:

For more complex examples see the Ant’s documentation.

1 Comments:

  • Greets to the webmaster of this wonderful site! Keep up the good work. Thanks.
    »

    By Anonymous Anonymous, at 7:53 PM  

Post a Comment

<< Home