ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bertrand Fontaine" <>
Subject Re: How to share an object between Tasks?
Date Wed, 07 Jan 2004 09:24:23 GMT
Hello Antoine,

Thank you very much for your reply. The solution you describe indeed works. 
The only thing I had to be careful at is to use the same loaderRef value for 
the typedefs and taskdefs. Otherwise, I am back with the ClassCastException 
problem due to the use of different class loaders.

Bertrand Fontaine

Bertrand Fontaine wrote:
>>I have a set of Tasks all requiring access to the very same class instance 
>>(a db connection in practice). How can I implement that with ANT?
>>So far, I have tried to implement this behaviour via a TaskContainer but I 
>>can't get back the TaskContainer instance from a Task, and hence the 
>>reference to the object I would like to share via the TaskContainer, as 
>>far as the TaskContainer and the Tasks are loaded in separate class 
>>Thank you,
>>Bertrand Fontaine
>Hi Bertrand,
>what I would do would be the following :
>- create a custom ant datatype encapsulating the object(s) that you want to 
>share between tasks,
>- use <typedef/> to declare your datatype (or put all your typedefs and 
>taskdefs into an antlib descriptor)
>-  then you can declare one or several instance(s) of your custom 
>datatype(s) with the id attribute set; in your custom tasks, add a an 
>attribute which would be a reference to your custom datatype
>something like this :
><typedef name="mydata" class=""/>
><taskdef name="mytask" class=""/>
><taskdef name="mytask2" class=""/>
><mydata property1="some.value" property2="some.othervalue" id="myid"/>
><mytask dataref="myid"/>
><mytask2 dataref="myid"/>
>in the source code of ant, this type of mechanisms is used a lot; for 
>instance the javac task can accept a reference to the path datatype in the 
>attribute classpathref, ...
>I have the impression that there are no explanations about custom datatypes 
>in the ant manual, this should exist.
>Most of what has been written about custom tasks also is true of custom 
>datatypes, the only difference is that an execute() method is not needed 
>for a datatype.
>Your custom datatypes may extend which 
>probably makes coding more easy. It is probably also not an absolute 
>Hopes this helps,

MSN Search, for relevant search results!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message