You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Dominique Devienne <DD...@lgc.com> on 2002/05/02 23:52:37 UTC

Bare minimum custom task

Stefan, and other ANT experts.

I vaguely remember Stefan stating that a task needn't derive from Task, but
simply needed a public void execute method, and setters as usual. I actually
just tried it with ANT 1.4.1, and it doesn't seem to work, with the
java.lang.NoSuchMethodException: setProject error message. I tried adding a
public void setProject(Object project) to my class, but ANT still cannot
find it, most probably because it looks for such a method that takes an ANT
project, not just an generic Object. There's no point in adding the method
ANT wants, since that creates a dependency on ANT, and I might as well
extend Task a that point. I know that the manual states that the first step
to create a custom task is to extends Task (1. Create a Java class that
extends org.apache.tools.ant.Task.), but wouldn't it be desirable to be able
to write custom task with no dependency on ANT?! And what would prevent it
technically? I'd appreciate any feedback. Thanks, --DD

public class EchoTask {

  private String _message = "<none>";

  public void setMessage(String message) {
    _message = message;
  }

  public void execute() {
    System.out.println(_message);
  }

} // END class EchoTask

  <target name="echotask"
          depends="compile-echotask">
    <taskdef name="echotask"
             classname="EchoTask"
             classpath="${classes}" />
    <echotask message="Hurra" />
  </target><!-- echotask -->

echotask:
Error setting project in class com.lgc.build.EchoTask

BUILD FAILED

P:\com_lgc\antx\build.xml:36: java.lang.NoSuchMethodException: setProject

Total time: 3 seconds


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bare minimum custom task

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Dominique Devienne" <DD...@lgc.com>
To: "'Ant Developers List'" <an...@jakarta.apache.org>
Sent: Thursday, May 02, 2002 2:52 PM
Subject: Bare minimum custom task


> Stefan, and other ANT experts.
>
> I vaguely remember Stefan stating that a task needn't derive from Task,
but
> simply needed a public void execute method, and setters as usual. I
actually
> just tried it with ANT 1.4.1, and it doesn't seem to work, with the
> java.lang.NoSuchMethodException: setProject error message. I tried adding
a
> public void setProject(Object project) to my class, but ANT still cannot
> find it, most probably because it looks for such a method that takes an
ANT
> project, not just an generic Object.

try ant 1.5


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bare minimum custom task

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 2 May 2002, Dominique Devienne <DD...@lgc.com> wrote:

> I vaguely remember Stefan stating that a task needn't derive from
> Task, but simply needed a public void execute method, and setters as
> usual.

See ConditionTask for an example.

> I actually just tried it with ANT 1.4.1, and it doesn't seem to
> work, with the java.lang.NoSuchMethodException: setProject error
> message.

Yep, you also needed a setProject(Project) method in 1.4.1, this is no
longer necessary in 1.5 AFAIK.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>