About
An optional task is a task which typically requires an external library to function.
Prerequisites
Adding library
Use Ant's own mechanisms for adding libraries:
- via command line argument -lib
- adding to ${user.home}/.ant/lib
- adding to ${ant.home}/lib
Declaration
Single Task
<?xml version="1.0"?>
<project name="OwnTaskExample" default="main" basedir=".">
<taskdef name="mytask" classname="com.mydomain.MyVeryOwnTask"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
</project>
Properties file
declare a bundle of tasks using a properties-file holding these taskname-ImplementationClass-pairs and <taskdef>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> <for ... />
Xml file
declare a bundle of tasks using a xml-file holding these taskname-ImplementationClass-pairs and <taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml" /> <for ... />
antlib.xml
declare a bundle of tasks using an xml-file named antlib.xml, XML-namespace and antlib: protocol handler
<project xmlns:ac="antlib:net.sf.antcontrib"/> <ac:for ... />