ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <>
Subject Re: building my own task...
Date Sat, 13 Apr 2002 01:43:16 GMT
Your Parameter class is subclassing from Task.  Parameter itself is not a
Task so simply remove it from the extends clause so that its just an Object.

Also, I would highly recommend you use the addXXX methods to inject your
Parameter subelements.  Like this:

 public void addParameter (com.tcheer.xalANTask.Parameter parameter) {
     this.m_params.add (parameter);

Ant will take of constructing your Parameter instance for you automatically
(as long as it can, of course).

Actually, on second glance, you're probably interpretting that its not
setting name/value appropriately prematurely.  It is not until the execute()
method when everything is completely populated.  And no, you don't need
getter methods, unless you need them yourself for some reason.  Could you
detail your findings more if this advice doesn't solve it all?


----- Original Message -----
From: "" <>
To: "ant-user" <>
Sent: Friday, April 12, 2002 9:24 PM
Subject: building my own task...

> Hi,
> I have been reading an article in a java magazine about how to create
> own ant task. Since then I am trying to excercise on it.
> I am defining a task, lets say "MyTask". MyTask has a sub element
> with both "name" and "value" attribute, so I have written an
> org.apache.ant.Task subclass named Parameter and in my "main" programm
> containing the execute method I also have the method "public
> com.myDomain.Parameter createParameter ()" and both "Parameter m_param"
> "Vector m_params" (since it should be possible to have more than one
> parameter...). The following implementation:
> public com.tcheer.xalANTask.Parameter createParameter () {
> //System.out.println ("+ createParameter");
> this.m_param = new Parameter ();
> this.m_params.add (this.m_param);
> //System.out.println("\tout");
> return m_param;
> }
> seems not to create a Parameter object with both name and value, but gives
> an empty object. Actually it is obvious
> Please I would appreciate any contribution from you if you think you can
> PS: The
> class Parameter extends org.apache.ant.Task {
> Parameter () {...}
> public void setName (String name) {...}
> public void setValue (String value) {...}
> //and the equivalent getMethods (though I think I don't need them, do I?)
> private String m_pname;
> private String m_pvalue;
> }
> --
> Eric Tchepannou
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

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

View raw message