ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject Bare minimum custom task
Date Thu, 02 May 2002 21:52:37 GMT
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:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message