View RSS Feed

My Java Tips

Using a custom task in Ant

Rate this Entry
by , 11-06-2011 at 06:53 PM (829 Views)
It is assumed that you have already defined a custom Ant task and wish to use it. In this post, I will show you how to do so.




You first need to define the task by giving it a name and telling Ant the classfile that implements it and any classpath setting required to locate that classfile. This is done using the taskdef task, like so:

<taskdef name="fileparser">classname="FileParser"
classpath="."/&gt;
</taskdef>

Now the task can now be used in the same way as Ant's core tasks. The following example shows how to use a custom task:

<!--?xml version="1.0"?-->
<project name="CustomTaskExample" default="main" basedir=".">
<taskdef name="fileparser">classname="FileParser"
classpath="."/&gt;
<target name="main">
<filesorter file="input.txt" tofile="output.txt">
</filesorter></target>
</taskdef></project>

Submit "Using a custom task in Ant" to Facebook Submit "Using a custom task in Ant" to Digg Submit "Using a custom task in Ant" to del.icio.us Submit "Using a custom task in Ant" to StumbleUpon Submit "Using a custom task in Ant" to Google

Tags: None Add / Edit Tags
Categories
Ant , XML

Comments