Creating an Ant Task with Eclipse
Creating an Ant Task with Eclipse
- Add ant.jar to your eclipse project.
- Create package to hold task classes. I recommend xxx.yyy.ant.tasks
- Create task class. Here is a simple one:
package com.affy.ant.tasks; import org.apache.tools.ant.*; public class HelloWorld extends Task { public void execute() throws BuildException { System.out.println("Hello World!"); } }
- Select Window, Preferences, Ant, Classpath
- Set ANT_HOME
- Add the folder where your class files are stored (xxx/build/classes, for example)
- Select Task, Add Task
- Assign a task name (ie, HelloWorld) to use in build.xml
- Select location (the folder xxx/build/classes for example)
</ol>
That's how easy it is to start writing your own Ant tasks. If you're going to invoke build.xml from within Eclipse, then you only need the following lines:
<target name="HelloWorld"> <HelloWorld/> </target>
Otherwise, you need to tell Ant where to find the class file. For example,
<path id="cp"> <pathelement path="xxx/build/classes"/> </path> <target name="HelloWorld"> <taskdef name="HelloWorld" classname="org.wwre.ant.tasks.HelloWorld" classpathref="cp"/> <HelloWorld/> </target>