Description
Adds a task or a data type definition to the current project
such that this new type or task can be used in the current project.
Tasks are any class that extend org.apache.tools.ant.Task or
a class that is adapted to a Task using an adapter class.
Data types are things like paths or
filesets that can be defined at
the project level and referenced via their ID attribute.
Custom data types usually need custom tasks to put them to good use.
Two attributes are needed to make a definition,
the name that identifies this data type uniquely, and the full
name of the class (including the packages) that implements this
type.
You can also define a group of definitions at once using the file or
resource attributes. These attributes point to files in the format of
Java property files or an xml format.
For property files each line defines a single data type in the
format:
typename=fully.qualified.java.classname
The xml format is described in the
Antlib
section.
Parameters
| Attribute |
Description |
Required |
| name |
the name of the data type |
Yes, unless the file or resource type
attributes have been specified. |
| classname |
the full class name implementing the data type |
Yes, unless file or resource
have been specified. |
| file |
Name of the file to load definitions from. |
No |
| resource |
Name of the resource to load definitions from.
If there is multiple resources of this name in the classpath, and the
format is "properties", the first resource will be loaded, otherwise
all the resources will be loaded.
|
No |
| format |
The format of the file or resource. The values
are "properties" or "xml". If the value is "properties" the file/resource
is a property file contains name to classname pairs. If the value
is "xml", the file/resource is an xml file/resource structured according
to Antlib.
The default is "properties" unless the file/resource name ends with
".xml", in which case the format attribute will have the value "xml".
(introduced in ant1.6)
|
No |
| classpath | the classpath to
use when looking up classname. | No |
| classpathref |
a reference to a classpath to use when looking up classname. |
No |
| loaderRef | the name of the loader that is
used to load the class, constructed from the specified classpath. Use this to
allow multiple tasks/types to be loaded with the same loader, so they can call
each other. ( introduced in ant1.5 ) |
No |
| onerror |
The action to take if there was a failure in defining the
type. The values are fail - cause a build exception, report,
output a warning, but continue, ignore, do nothing. The default
is fail.
(introduced in ant1.6)
|
No |
| adapter |
A class that is used to adapt the defined class to
another interface/class. The adapter class must implement the interface
"org.apache.tools.ant.TypeAdapter". The adapter class will be used
to wrap the defined class unless the defined class implements/extends
the class defined by the attribute "adaptto".
If "adaptto" is not set,
the defined class will always be wrapped.
(introduced in ant1.6)
|
No |
| adaptto |
This attribute is used in conjunction with the
adapter attribute.
If the defined class does not implement/extend the interface/class
specified by this attribute, the adaptor class will be used
to wrap the class.
(introduced in ant1.6)
|
No |
| uri |
The uri that this definition should live in.
since Ant1.6
|
No |
Parameters specified as nested elements
classpath
Typedef's classpath attribute is a
PATH like structure and can also be set
via a nested classpath element.
Examples
The following fragment defines define a type called urlset.
<typedef name="urlset" classname="com.mydomain.URLSet"/>
The data type is now available to Ant. The
class com.mydomain.URLSet implements this type.
Assuming a class org.acme.ant.RunnableAdapter that
extends Task and implements org.apache.tools.ant.TypeAdapter,
and in the execute method invokes run on the proxied object,
one may use a Runnable class as an Ant task. The following fragment
defines a task called runclock.
<typedef name="runclock"
classname="com.acme.ant.RunClock"
adapter="org.acme.ant.RunnableAdapter"/>
The following fragment shows the use of the classpathref and
loaderref to load up two definitions.
<path id="lib.path">
<fileset dir="lib" includes="lib/*.jar"/>
</path>
<typedef name="filter1"
classname="org.acme.filters.Filter1"
classpathref="lib.path"
loaderref="lib.path.loader"
/>
<typedef name="filter2"
classname="org.acme.filters.Filter2"
loaderref="lib.path.loader"
/>
Source: Apache Ant
Related Tips
|
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.