ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: Ant Task - Details
Date Tue, 19 Aug 2003 08:51:01 GMT
Little example:

build.xml:
----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="use">

    <property name="src.dir" value="src"/>
    <property name="classes.dir" value="classes"/>
    <property name="lib.name" value="mytasks.jar"/>

    <target name="clean" description="Delete all generated files">
        <delete dir="${classes.dir}" failonerror="false"/>
        <delete file="${lib.name}"/>
    </target>

    <target name="compile" description="Compiles the Task">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>

    <target name="jar" description="JARs the Task" depends="compile">
        <jar destfile="${lib.name}" basedir="${classes.dir}"/>
    </target>

    <target name="use" description="Use the Task" depends="jar">
        <taskdef name="mytask" classname="com.mycompany.ant.MyFirstTask"
classpath="${lib.name}"/>
        <mytask/>
    </target>

</project>




/src/com/mycompany/ant/MyFirstTask.java:
----------------------------------------
package com.mycompany.ant;

import org.apache.tools.ant.Task;

public class MyFirstTask extends Task {
    public void execute() {
        log("Hello World");
    }
}



If you are in the directory containing the build.xml and type in "ant"
all should be done.



C:\tmp\anttests\MyFirstTask>ant

Buildfile: build.xml

compile:
    [mkdir] Created dir: C:\tmp\anttests\MyFirstTask\classes
    [javac] Compiling 1 source file to C:\tmp\anttests\MyFirstTask\classes

jar:
      [jar] Building jar: C:\tmp\anttests\MyFirstTask\mytasks.jar

use:
   [mytask] Hello World

BUILD SUCCESSFUL
Total time: 10 seconds
C:\tmp\anttests\MyFirstTask>



Jan


> -----Original Message-----
> From: Andrei [mailto:andrei@netrom.ro]
> Sent: Tuesday, August 19, 2003 10:39 AM
> To: Ant Users List
> Subject: Re: Ant Task - Details
> 
> 
>             I understand that the problem consist in setting 
> the path, but i
> still have the problem. I don't know what is wrong. I need an 
> example for
> the
> 
> taskdef  statement.
> 
>     I compiled my class, i  also made more jar files 
> containing the class.
> 
>         I'll give you the directory for the classes.
> 
> the direcory D:\Work\Uni-D\main\build\classes\netrom contains the file
> MyVeryOwnTask.class
> the directory D:\Work\Uni-D\main\build contains the jar file 
> : mytask.jar
> wich have the directory netrom inside and MyVeryOwnTask.class 
> in it. You
> have attached the uni-d.jar file.
> 
> 
>                                                             Andrei
> 
> ----- Original Message -----
> From: "Simon Bretin" <simon@anyware-tech.com>
> To: "Ant Users List" <user@ant.apache.org>
> Sent: Tuesday, August 19, 2003 9:51 AM
> Subject: Re: Ant Task - Details
> 
> 
> > Hi Andrei,
> >
> > This means that the class you implemented is not available in the
> classpath.
> >
> > Either you change your setup so that your be.unid.generate 
> package is
> > available within your system classpath,
> > Either you slightly modify your <taskdef> definition, and add a
> > classpath child note containing this package.
> >
> > Hope this helps,
> >
> > Simon.
> >
> > Andrei wrote:
> >
> > >        Simon, i 've already done that, but i think 
> something missing.
> > >This is what i've done so far.
> > >
> > >        I have a project containing the package  
> be.unid.generate and i
> want to write an Ant Task to perform some things. I made a class named
> > >MyVeryOwnTask in the package extending the Task class.
> > >
> > >Here is the class code:
> > >
> > >
> > >package be.unid.generate;
> > >
> > >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;
> > >    }
> > >}
> > >
> > >        In the Build File I added at the bigining the following:
> > >
> > >
> > >         <taskdef name="mytask"
> > >            classname="be.unid.generate.MyVeryOwnTask"
> > >         />
> > >
> > >
> > >and the target:
> > >
> > >    <target name="task">
> > >      <mytask message="Hello World! MyVeryOwnTask works!"/>
> > >    </target>
> > >
> > >and at build time i get the error :
> > >
> > >taskdef class be.unid.generate.MyVeryOwnTask cannot be 
> found and build
> process stops
> > >
> > >
> > >What this means and what can i do?
> > >
> > >
> > >
> Andrei
> > >
> > >
> > >
> > >
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> 
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message