You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Gale, Paul" <pg...@clicktactics.com> on 2001/09/28 21:35:42 UTC

Newbie question

Hi,

Apologies if this the wrong forum:

I've been trying out Ant using the example from the doc, namely:

package com.mydomain;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class MyVeryOwnTask extends Task {
  private String msg;

  // The method executing the task
  public void execute() throws BuildException {
    System.out.println(msg);
  }

  // The setter for the "message" attribute
  public void setMessage(String msg) {
    this.msg = msg;
  }
}

and using the sample build.xml file provided. 

<?xml version="1.0"?>

<project name="OwnTaskExample" default="main" basedir=".">
  <taskdef name="mytask" classname="com.mydomain.MyVeryOwnTask"/>

  <target name="main">
    <mytask message="Hello World! MyVeryOwnTask works!"/> 
  </target>
</project>


However, it fails to run, with the error:
 taskdef class com.mydomain.MyVeryOwnTask cannot be found

I have the class file in the same directory from where build.xml is executed
and on the classpath. 

I've tried removing the 'taskdef' element from the build.xml file and added
the MyVeryOwnTask.class file using jar.exe to jakarta-ant-1.4-optional.jar
and to the default properties file. Still nothing. 

What am I missing here? Something blatant no doubt, but I'm out of ideas.
I've checked all the doc and can't find a solution.

All help is much appreciated.

Paul



Re: Newbie question

Posted by Diane Holt <ho...@yahoo.com>.
I wouldn't recommend putting it in the optional jar-file and adding it to
defaults.properties, since it's best to avoid changing the off-the-shelf
Ant stuff. Instead, try jar'ing up com/mydomain/MyVeryOwnTask.class into
my.jar (or whatever) and putting that into $ANT_HOME/lib.

Diane

--- "Gale, Paul" <pg...@clicktactics.com> wrote:
> Hi,
> 
> Apologies if this the wrong forum:
> 
> I've been trying out Ant using the example from the doc, namely:
> 
> package com.mydomain;
> 
> import org.apache.tools.ant.BuildException;
> import org.apache.tools.ant.Task;
> 
> public class MyVeryOwnTask extends Task {
>   private String msg;
> 
>   // The method executing the task
>   public void execute() throws BuildException {
>     System.out.println(msg);
>   }
> 
>   // The setter for the "message" attribute
>   public void setMessage(String msg) {
>     this.msg = msg;
>   }
> }
> 
> and using the sample build.xml file provided. 
> 
> <?xml version="1.0"?>
> 
> <project name="OwnTaskExample" default="main" basedir=".">
>   <taskdef name="mytask" classname="com.mydomain.MyVeryOwnTask"/>
> 
>   <target name="main">
>     <mytask message="Hello World! MyVeryOwnTask works!"/> 
>   </target>
> </project>
> 
> 
> However, it fails to run, with the error:
>  taskdef class com.mydomain.MyVeryOwnTask cannot be found
> 
> I have the class file in the same directory from where build.xml is
> executed
> and on the classpath. 
> 
> I've tried removing the 'taskdef' element from the build.xml file and
> added
> the MyVeryOwnTask.class file using jar.exe to
> jakarta-ant-1.4-optional.jar
> and to the default properties file. Still nothing. 
> 
> What am I missing here? Something blatant no doubt, but I'm out of
> ideas.
> I've checked all the doc and can't find a solution.
> 
> All help is much appreciated.
> 
> Paul
> 
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Listen to your Yahoo! Mail messages from any phone.
http://phone.yahoo.com