You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Gary Shea <sh...@gtsdesign.com> on 2001/08/22 21:05:31 UTC

taskdef and declarations

Hi --

Today I had the pleasure of getting a custom taskdef working, wow!
Very slick.

My only issue is that I can't seem to use property values (e.g.,
${jars.dir}) in the taskdef element.  Am I just missing something, or
is this really not possible?

Regards,

	Gary Shea
	shea@gtsdesign.com


manual request: evaluation order within

Posted by Gary Shea <sh...@gtsdesign.com>.
I have a small suggestion for the manual.  I was unable to find
mention of evaluation order for the child elements of the <project>
element.

My problem was with <taskdef> -- I didn't realize that a taskdef
anywhere in the file would actually be evaluated before any <target>
if it was not contained in a target.  Just now, while re-reading the
manual to see if I missed evaluation-order information, I saw the
<path> element which can appear as a direct child of of <project>.
Evaluation order is critical if ${...} substitutions are being used.

It might be useful to have a short paragraph near the top of "Using
Ant" defining evaluation order.  I would write it, but I don't know
enough about how evaluation works.  Sorry...

I'm really impressed by the growth of Ant.  It's getting more useful
all the time!

Thanks,

	Gary


Re: taskdef and declarations

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 23 Aug 2001, Gary Shea <sh...@gtsdesign.com> wrote:

> Here's what I initially tried, which does not work with 1.3:
> 
>     <target name="init">
> 	<property name="jars.dir" value="..."/>
>     </target>
> 
>     <taskdef name="sqlfwk3"
> 	    classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
> 	<classpath>
> 	    <pathelement
> 	    location="${jars.dir}/sqlfwk3-taskdef.jar"/>
> 	</classpath>
>     </taskdef>

<taskdef> is not inside a target, so it gets run before any target -
your property is not defined.

> Is that the expected behavior?

Yes.

Stefan

Re: taskdef and declarations

Posted by Gary Shea <sh...@gtsdesign.com>.
Stefan Bodewig (bodewig@apache.org) wrote:
> On Wed, 22 Aug 2001, Gary Shea <sh...@gtsdesign.com> wrote:
>
> > What I want to write is:
> >
> >     <taskdef name="sqlfwk3"
> >             classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
> >         <classpath>
> >             <pathelement
> >             location="${jars.dir}/sqlfwk3-taskdef.jar"/>
> >         </classpath>
> >     </taskdef>
> >
> > but ${jars.dir} (which is actually coming from the calling
> > buildfile) doesn't seem to get substituted.
>
> It should - and your task won't even notice.  If you get a literal
> ${jars.dir}, this means the property is not set.  Try <echo>ing it
> before the taskdef.
>
> It must be defined, before the <taskdef> gets executed.
>
> Stefan

Here's what I initially tried, which does not work with 1.3:

    <target name="init">
	<property name="jars.dir" value="..."/>
    </target>

    <taskdef name="sqlfwk3"
	    classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
	<classpath>
	    <pathelement
	    location="${jars.dir}/sqlfwk3-taskdef.jar"/>
	</classpath>
    </taskdef>

I get a ClassNotFoundException on the class given in the classname
attribute.

Here's a slightly different version that works just fine:

    <target name="init">
	<property name="jars.dir" value="..."/>
    </target>

    <target name="sqlfwk3" depends="init">
	<taskdef name="sqlfwk3"
		classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
	    <classpath>
		<pathelement
		location="${jars.dir}/sqlfwk3-taskdef.jar"/>
	    </classpath>
	</taskdef>
    </target>

Is that the expected behavior?

Thanks!

	Gary


Re: taskdef and declarations

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 22 Aug 2001, Gary Shea <sh...@gtsdesign.com> wrote:

> What I want to write is:
> 
>     <taskdef name="sqlfwk3"
>             classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
>         <classpath>
>             <pathelement
>             location="${jars.dir}/sqlfwk3-taskdef.jar"/>
>         </classpath>
>     </taskdef>
> 
> but ${jars.dir} (which is actually coming from the calling
> buildfile) doesn't seem to get substituted.

It should - and your task won't even notice.  If you get a literal
${jars.dir}, this means the property is not set.  Try <echo>ing it
before the taskdef.

It must be defined, before the <taskdef> gets executed.

Stefan 

RE: taskdef and declarations

Posted by Gary Shea <sh...@gtsdesign.com>.
Supriya Saha (ssaha@bowcutter.com) wrote:
> Yes it's a problem. My solution is that just before calling the ant task
> define a local property using the parameter ${jars.dir} and use the local
> property.
> Let me know whether it solves your problem or not.
>
> Best of luck,
> Supriyo

Hi Supriyo --

I just tried putting the taskdef inside the target where it's
used, and I can use the parameters there!  I had it wrong before
(sorry!) that the parameters were coming from a calling buildfile,
this one is standalone.  I had tried:

    <target name="init">
	<property name="jars.dir" value="..."/>
    </target>

    <taskdef name="sqlfwk3"
            classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
        <classpath>
            <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
        </classpath>
    </taskdef>

which didn't work, but:

    <target name="init">
	<property name="jars.dir" value="..."/>
    </target>

    target name="sqlfwk3" depends="init">
	<taskdef name="sqlfwk3"
		classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
	    <classpath>
		<pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
	    </classpath>
	</taskdef>
	<sqlfwk3.... />
    </target>

works fine!

Thanks for your help!

	Gary


> -----Original Message-----
> From: Gary Shea [mailto:shea@gtsdesign.com]
> Sent: Wednesday, August 22, 2001 3:33 PM
> To: ant-user@jakarta.apache.org
> Subject: Re: taskdef and <property> declarations
>
> Oops, I don't think I gave enough details!
>
> What I want to write is:
>
>     <taskdef name="sqlfwk3"
>             classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
>         <classpath>
>             <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
>         </classpath>
>     </taskdef>
>
> but ${jars.dir} (which is actually coming from the calling
> buildfile) doesn't seem to get substituted.  If I replace the
> ${jars.dir} in the taskdef with its value, everything works.  I know
> it's not a problem with ${jars.dir} itself, as the buildfile uses it
> successfully outside the taskdef element.
>
> Regards,
>
>         Gary
>
> T Master (tmaster@iknowledgeinc.com) wrote:
> > You did imeplement a setFoo() method for an attribute called foo ?
> > e.g. foo="blah"
> >
> > That's how i did it.
> >
> >
> > ----- Original Message -----
> > From: "Gary Shea" <sh...@gtsdesign.com>
> > To: <an...@jakarta.apache.org>
> > Sent: Wednesday, August 22, 2001 1:05 PM
> > Subject: taskdef and <property> declarations
> >
> >
> > > Hi --
> > >
> > > Today I had the pleasure of getting a custom taskdef working, wow!
> > > Very slick.
> > >
> > > My only issue is that I can't seem to use property values (e.g.,
> > > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > > is this really not possible?
> > >
> > > Regards,
> > >
> > > Gary Shea
> > > shea@gtsdesign.com
> > >
> >
> >
>
>


RE: taskdef and declarations

Posted by Gary Shea <sh...@gtsdesign.com>.
Supriya Saha (ssaha@bowcutter.com) wrote:
> Yes it's a problem. My solution is that just before calling the ant task
> define a local property using the parameter ${jars.dir} and use the local
> property.
> Let me know whether it solves your problem or not.
>
> Best of luck,
> Supriyo

I'm not sure I understand.  The property is being used in order to
find the jar containing the task, which is needed when ant reads the
file and immediately creates an instance of the task:

   <taskdef name="sqlfwk3"
           classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
       <classpath>
           <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
       </classpath>
    </taskdef>

I can't put off use of the classpath!

Can you explain further please?

	Gary

> -----Original Message-----
> From: Gary Shea [mailto:shea@gtsdesign.com]
> Sent: Wednesday, August 22, 2001 3:33 PM
> To: ant-user@jakarta.apache.org
> Subject: Re: taskdef and <property> declarations
>
> Oops, I don't think I gave enough details!
>
> What I want to write is:
>
>     <taskdef name="sqlfwk3"
>             classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
>         <classpath>
>             <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
>         </classpath>
>     </taskdef>
>
> but ${jars.dir} (which is actually coming from the calling
> buildfile) doesn't seem to get substituted.  If I replace the
> ${jars.dir} in the taskdef with its value, everything works.  I know
> it's not a problem with ${jars.dir} itself, as the buildfile uses it
> successfully outside the taskdef element.
>
> Regards,
>
>         Gary
>
> T Master (tmaster@iknowledgeinc.com) wrote:
> > You did imeplement a setFoo() method for an attribute called foo ?
> > e.g. foo="blah"
> >
> > That's how i did it.
> >
> >
> > ----- Original Message -----
> > From: "Gary Shea" <sh...@gtsdesign.com>
> > To: <an...@jakarta.apache.org>
> > Sent: Wednesday, August 22, 2001 1:05 PM
> > Subject: taskdef and <property> declarations
> >
> >
> > > Hi --
> > >
> > > Today I had the pleasure of getting a custom taskdef working, wow!
> > > Very slick.
> > >
> > > My only issue is that I can't seem to use property values (e.g.,
> > > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > > is this really not possible?
> > >
> > > Regards,
> > >
> > > Gary Shea
> > > shea@gtsdesign.com
> > >
> >
> >
>
>


RE: taskdef and declarations

Posted by Supriya Saha <ss...@bowcutter.com>.
Yes it's a problem. My solution is that just before calling the ant task
define a local property using the parameter ${jars.dir} and use the local
property.
Let me know whether it solves your problem or not.

Best of luck,
Supriyo

-----Original Message-----
From: Gary Shea [mailto:shea@gtsdesign.com]
Sent: Wednesday, August 22, 2001 3:33 PM
To: ant-user@jakarta.apache.org
Subject: Re: taskdef and <property> declarations

Oops, I don't think I gave enough details!

What I want to write is:

    <taskdef name="sqlfwk3"
            classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
        <classpath>
            <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
        </classpath>
    </taskdef>

but ${jars.dir} (which is actually coming from the calling
buildfile) doesn't seem to get substituted.  If I replace the
${jars.dir} in the taskdef with its value, everything works.  I know
it's not a problem with ${jars.dir} itself, as the buildfile uses it
successfully outside the taskdef element.

Regards,

        Gary

T Master (tmaster@iknowledgeinc.com) wrote:
> You did imeplement a setFoo() method for an attribute called foo ?
> e.g. foo="blah"
>
> That's how i did it.
>
>
> ----- Original Message -----
> From: "Gary Shea" <sh...@gtsdesign.com>
> To: <an...@jakarta.apache.org>
> Sent: Wednesday, August 22, 2001 1:05 PM
> Subject: taskdef and <property> declarations
>
>
> > Hi --
> >
> > Today I had the pleasure of getting a custom taskdef working, wow!
> > Very slick.
> >
> > My only issue is that I can't seem to use property values (e.g.,
> > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > is this really not possible?
> >
> > Regards,
> >
> > Gary Shea
> > shea@gtsdesign.com
> >
>
>


Re: taskdef and declarations

Posted by Gary Shea <sh...@gtsdesign.com>.
Oops, I don't think I gave enough details!

What I want to write is:

    <taskdef name="sqlfwk3"
            classname="com.gtsdesign.sqlfwk3.ant.Sqlfwk3Taskdef" >
        <classpath>
            <pathelement location="${jars.dir}/sqlfwk3-taskdef.jar"/>
        </classpath>
    </taskdef>

but ${jars.dir} (which is actually coming from the calling
buildfile) doesn't seem to get substituted.  If I replace the
${jars.dir} in the taskdef with its value, everything works.  I know
it's not a problem with ${jars.dir} itself, as the buildfile uses it
successfully outside the taskdef element.

Regards,

	Gary

T Master (tmaster@iknowledgeinc.com) wrote:
> You did imeplement a setFoo() method for an attribute called foo ?
> e.g. foo="blah"
>
> That's how i did it.
>
>
> ----- Original Message -----
> From: "Gary Shea" <sh...@gtsdesign.com>
> To: <an...@jakarta.apache.org>
> Sent: Wednesday, August 22, 2001 1:05 PM
> Subject: taskdef and <property> declarations
>
>
> > Hi --
> >
> > Today I had the pleasure of getting a custom taskdef working, wow!
> > Very slick.
> >
> > My only issue is that I can't seem to use property values (e.g.,
> > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > is this really not possible?
> >
> > Regards,
> >
> > Gary Shea
> > shea@gtsdesign.com
> >
>
>


RE: taskdef and declarations

Posted by Supriya Saha <ss...@bowcutter.com>.
If you go through Ant documentation and the FAQ, you will see that it is
suggested as a permanent solution for custom tasks. I just referred to that.
Supriyo

-----Original Message-----
From: T Master [mailto:tmaster@iknowledgeinc.com]
Sent: Wednesday, August 22, 2001 3:32 PM
To: ant-user@jakarta.apache.org
Subject: Re: taskdef and <property> declarations

Don't include it in ant.jar.  When you update your ant.jar you will have
problems and curse for a few hours until you realise what a bozo you were in
putting the properties file there :p

Simpler to declare it in your build file.  IMHO.

T Master

----- Original Message -----
From: "Supriya Saha" <ss...@bowcutter.com>
To: <an...@jakarta.apache.org>
Sent: Wednesday, August 22, 2001 1:30 PM
Subject: RE: taskdef and <property> declarations


> Where have you defined the property? For custom ant task, in taskdef you
> have to provide a name of the task and the classname which is the actual
> reference (including the package reference) to the ant task class. Also
you
> have to include the jar (containing your custom task) under ant.home/lib
> directory. A more permanent way of doing it is to include your task in the
> default.properties file for Taskdefs in ant.jar. In that case you don't
have
> to specify taskdef in your xml file.
> Supriyo
>
> -----Original Message-----
> From: T Master [mailto:tmaster@iknowledgeinc.com]
> Sent: Wednesday, August 22, 2001 3:18 PM
> To: ant-user@jakarta.apache.org
> Subject: Re: taskdef and <property> declarations
>
> You did imeplement a setFoo() method for an attribute called foo ?
> e.g. foo="blah"
>
> That's how i did it.
>
>
> ----- Original Message -----
> From: "Gary Shea" <sh...@gtsdesign.com>
> To: <an...@jakarta.apache.org>
> Sent: Wednesday, August 22, 2001 1:05 PM
> Subject: taskdef and <property> declarations
>
>
> > Hi --
> >
> > Today I had the pleasure of getting a custom taskdef working, wow!
> > Very slick.
> >
> > My only issue is that I can't seem to use property values (e.g.,
> > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > is this really not possible?
> >
> > Regards,
> >
> > Gary Shea
> > shea@gtsdesign.com
> >
>


Re: taskdef and declarations

Posted by T Master <tm...@iknowledgeinc.com>.
Don't include it in ant.jar.  When you update your ant.jar you will have
problems and curse for a few hours until you realise what a bozo you were in
putting the properties file there :p

Simpler to declare it in your build file.  IMHO.

T Master

----- Original Message -----
From: "Supriya Saha" <ss...@bowcutter.com>
To: <an...@jakarta.apache.org>
Sent: Wednesday, August 22, 2001 1:30 PM
Subject: RE: taskdef and <property> declarations


> Where have you defined the property? For custom ant task, in taskdef you
> have to provide a name of the task and the classname which is the actual
> reference (including the package reference) to the ant task class. Also
you
> have to include the jar (containing your custom task) under ant.home/lib
> directory. A more permanent way of doing it is to include your task in the
> default.properties file for Taskdefs in ant.jar. In that case you don't
have
> to specify taskdef in your xml file.
> Supriyo
>
> -----Original Message-----
> From: T Master [mailto:tmaster@iknowledgeinc.com]
> Sent: Wednesday, August 22, 2001 3:18 PM
> To: ant-user@jakarta.apache.org
> Subject: Re: taskdef and <property> declarations
>
> You did imeplement a setFoo() method for an attribute called foo ?
> e.g. foo="blah"
>
> That's how i did it.
>
>
> ----- Original Message -----
> From: "Gary Shea" <sh...@gtsdesign.com>
> To: <an...@jakarta.apache.org>
> Sent: Wednesday, August 22, 2001 1:05 PM
> Subject: taskdef and <property> declarations
>
>
> > Hi --
> >
> > Today I had the pleasure of getting a custom taskdef working, wow!
> > Very slick.
> >
> > My only issue is that I can't seem to use property values (e.g.,
> > ${jars.dir}) in the taskdef element.  Am I just missing something, or
> > is this really not possible?
> >
> > Regards,
> >
> > Gary Shea
> > shea@gtsdesign.com
> >
>


RE: taskdef and declarations

Posted by Supriya Saha <ss...@bowcutter.com>.
Where have you defined the property? For custom ant task, in taskdef you
have to provide a name of the task and the classname which is the actual
reference (including the package reference) to the ant task class. Also you
have to include the jar (containing your custom task) under ant.home/lib
directory. A more permanent way of doing it is to include your task in the
default.properties file for Taskdefs in ant.jar. In that case you don't have
to specify taskdef in your xml file.
Supriyo

-----Original Message-----
From: T Master [mailto:tmaster@iknowledgeinc.com]
Sent: Wednesday, August 22, 2001 3:18 PM
To: ant-user@jakarta.apache.org
Subject: Re: taskdef and <property> declarations

You did imeplement a setFoo() method for an attribute called foo ?
e.g. foo="blah"

That's how i did it.


----- Original Message -----
From: "Gary Shea" <sh...@gtsdesign.com>
To: <an...@jakarta.apache.org>
Sent: Wednesday, August 22, 2001 1:05 PM
Subject: taskdef and <property> declarations


> Hi --
>
> Today I had the pleasure of getting a custom taskdef working, wow!
> Very slick.
>
> My only issue is that I can't seem to use property values (e.g.,
> ${jars.dir}) in the taskdef element.  Am I just missing something, or
> is this really not possible?
>
> Regards,
>
> Gary Shea
> shea@gtsdesign.com
>


Re: taskdef and declarations

Posted by T Master <tm...@iknowledgeinc.com>.
You did imeplement a setFoo() method for an attribute called foo ?
e.g. foo="blah"

That's how i did it.


----- Original Message ----- 
From: "Gary Shea" <sh...@gtsdesign.com>
To: <an...@jakarta.apache.org>
Sent: Wednesday, August 22, 2001 1:05 PM
Subject: taskdef and <property> declarations


> Hi --
> 
> Today I had the pleasure of getting a custom taskdef working, wow!
> Very slick.
> 
> My only issue is that I can't seem to use property values (e.g.,
> ${jars.dir}) in the taskdef element.  Am I just missing something, or
> is this really not possible?
> 
> Regards,
> 
> Gary Shea
> shea@gtsdesign.com
>