Nested types in a custom ant task

N

Nick

Hi All,

I'm creating a custom ant task and would like to have nested elements
inside this task that indicate a list of exporters that should be used
to export the results of the ant task.

Suffice to say there is an interface called

com.company.Exporter

and some classes:

com.company.FirstCustomExporter implements Exporter
com.company.SecondCustomExporter implements Exporter

....that export different things

According to the Ant manual I should be able to have an Ant task like
so:

class MyAntTask extends Task {

...
public void add( Exporter ex ) {
...
}

}

And then have in my build file

<taskdef name="myanttask" class="com.company.MyAntTask" />
<typedef name="firstcustomexporter"
class="com.company.FirstCustomExporter" />
<typedef name="secondcustomexporter"
class="com.company.SecondCustomExporter" />

<myanttask>
<firstcustomexporter />
<secondcustomexporter />
</myanttask>

However when I try to do things this way all I get is:

'myanttask' doesn't support the nested element 'firstcustomexporter'

What is wrong with my logic? I even copied and pasted the code from
the "Writing your own task" tutorial and it doesn't work.

This is not an issue with classpaths, I've run ant -debug and you can
see all the relevant classes being loaded from the right places....

This is truly frustrating and any help would be greatly appreciated...
Surely writing an ant task is not this difficult, what have I missed??

Kind Regards,
Nick
 
J

John B. Matthews

Nick said:
I'm creating a custom ant task and would like to have nested elements
inside this task that indicate a list of exporters that should be used
to export the results of the ant task.

Suffice to say there is an interface called

com.company.Exporter

and some classes:

com.company.FirstCustomExporter implements Exporter
com.company.SecondCustomExporter implements Exporter

...that export different things

According to the Ant manual I should be able to have an Ant task like
so:

class MyAntTask extends Task {

...
public void add( Exporter ex ) {
...
}

}

And then have in my build file

<taskdef name="myanttask" class="com.company.MyAntTask" />
<typedef name="firstcustomexporter"
class="com.company.FirstCustomExporter" />
<typedef name="secondcustomexporter"
class="com.company.SecondCustomExporter" />

<myanttask>
<firstcustomexporter />
<secondcustomexporter />
</myanttask>

However when I try to do things this way all I get is:

'myanttask' doesn't support the nested element 'firstcustomexporter'

What is wrong with my logic? I even copied and pasted the code from
the "Writing your own task" tutorial and it doesn't work.

This is not an issue with classpaths, I've run ant -debug and you can
see all the relevant classes being loaded from the right places....

This is truly frustrating and any help would be greatly appreciated...
Surely writing an ant task is not this difficult, what have I missed??

Just a guess: If your task contains other tasks as nested elements, do
you need to implement TaskContainer:

<http://ant.apache.org/manual/develop.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top