ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miles Parker <>
Subject Dynamic task parsing
Date Tue, 21 Sep 2004 01:32:37 GMT

I've been trying to implement a task that would allow one to specify a class and 
then values for the properties of that class as attributes. So follows a very 
simple example -- and yes, I know that I could accomplish this example task in 
some relativly easy ways but there is more to the task. I could also do this 
employing some kind of object/xml mapping, but I want to do it from within ant..

Assume with properties val1 and val2. RunJavaTask simply extends 
Task or UnknownElement with the className property and different logic I've 
tried. (See below.)

<project name="Run Class" default="run">
     <taskdef name="runjavaclass" classpath="${dir.classpath}" 

     <target name="run some class">
         <runjavaclass className="" val1="Hello" val2="World">

Or, something like..

     <target name="run some class">
         <runjavaclass className="">
             <properties val1="Hello" val2="World"/>

Or other variations, including using elements, would work just as well. What I 
don't want to do is something like:

     <target name="run some class">
         <runjavaclass modelName="">
             <property name="val1" value="Hello"/>
             <property name="val2" value="World"/>

And ideally you would still be able to report a parse error, e.g. "Property 
'val3' doesn't exist in

Now, I've done a fair amount of reading up on the Task life cycle, including 
this excellent piece:

And I'm thinking that somehow I need to use UnknownElement and 
RuntimeConfiguration to get this working. However everything I've tried so far 
(overriding maybeConfigure, for example) has got me stuck in a parsing/runtime 
chicken-and-egg problem; e.g. I can't find out what the class to instantiate is 
until it is too late to properly parse the remaining attributes.

thanks for any ideas or esp. usage examples..don't know if I've missed something 


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

View raw message