You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jon Svede <js...@yahoo.com> on 2011/03/14 17:50:11 UTC
How to reference elements in custom task
Hi,
I have a set of custom tasks that need to be able to load dependencies from
<path> element. In my case my tasks may be defined in <taskdef> declarations or
via adding the jar file to the $ANT_HOME/lib dir.
This is what I want to have in the build.xml file:
<path name="some.path">
<pathelement location="some/local/dir/my.jar"/>
</path>
<target name="mytarget">
<someCustomTask classpathref="some.path"/>
</target>
In this example the task someCustomTask needs to be able to have classes from
the path 'some.path' to be able to execute.
I've been searching for examples or forum posts related to this but everything
I've found isn't working. Does anyone have a good explanation of this is done
or are there some docs on this?
Thanks in advance,
Jon
Re: How to reference elements in custom task
Posted by Jon Svede <js...@yahoo.com>.
Peter,
Thanks for the clarification, I appreciate it!
Sincerely,
Jon
________________________________
From: Peter Reilly <pe...@gmail.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Mon, March 14, 2011 12:27:25 PM
Subject: Re: How to reference <path> elements in custom task
There is nothing in ant that would do that (it was
planned at one stage).
In any case, it is not good practice to place
any extra jars into $ANT_HOME/lib, as this
makes reproducible builds difficult.
The ant-classloader task
http://enitsys.sourceforge.net/ant-classloadertask/ (written by
Rainer Noack) will
solve your problem, but at the "cost" of an extra jar.
Peter
On Mon, Mar 14, 2011 at 5:56 PM, Jon Svede <js...@yahoo.com> wrote:
> Wolfgang,
>
> Thanks for the reply.
>
> So originally I had my tasks working by defining a <path> entry that included
>my
> tasks and their dependencies. This worked fine without me having to do
anything
> other than define <taskdef> entries in my build file.
>
> Then I was asked to make it so that my tasks could be put into the
>$ANT_HOME/lib
> dir but be able to define the dependencies in the build.xml. This did not
>work.
> My tasks would be found, but the dependencies were not. I am guessing it's
> parentage thing: my classes are higher in the classloader parentage than it's
> dependencies. I then tested this by adding all the classes my tasks depend on
> to my jar file in the $ANT_HOME/lib - that worked too, but it failed when I
> added classes that implement my interfaces. In this case, I think it is
again
> some sort of parentage issue.
>
> My specific use case is as follows:
>
> I have a set of ant tasks that depend on Apache POI for spreadsheet testing.
I
> do not want to package the POI classes into my jar. Secondarily, my jar file
>of
> tasks defines an interface for users to implement; those implementations can
be
> given to my ant tasks for execution.
>
> I thought, perhaps incorrectly, that if my tasks could access the path element
> and then "inject" those references into the execution environment I'd be able
>to
> move forward. Am I mistaken?
>
> Most of what I found either didn't apply or I didn't understand. What I did
> find outside of that didn't seem to help. I found a reference to a
Classloader
> task written by Peter Reilly but this is again an external task. I have been
> under the assumption that I would be able to resolve my issue with the core
ant
> tasks rather than requiring additional non-core jars.
>
> Does that give you more insight into my problem? It's entirely possible that
> what I want to do isn't feasible but that is what I am basically asking: can I
> do this as I've described or is there another, more preferable way to
>accomplish
> this?
>
> Sincerely,
>
> Jon
>
>
>
>
> ________________________________
> From: wolfgang haefelinger <wh...@gmail.com>
> To: Ant Users List <us...@ant.apache.org>
> Sent: Mon, March 14, 2011 11:21:57 AM
> Subject: Re: How to reference <path> elements in custom task
>
> Jon,
>
>> <someCustomTask classpathref="some.path"/>
>
> This attribute of yours, "classpathref" is not a standard attribute:
> http://ant.apache.org/manual/Tasks/common.html
>
>> I've been searching for examples or forum posts related to this but
everything
>> I've found isn't working.
>
> How about sharing what you've found and what exactly is not working?
>
> // Wolfgang
>
> On Mon, Mar 14, 2011 at 5:50 PM, Jon Svede <js...@yahoo.com> wrote:
>> Hi,
>>
>> I have a set of custom tasks that need to be able to load dependencies from
>> <path> element. In my case my tasks may be defined in <taskdef> declarations
>>or
>> via adding the jar file to the $ANT_HOME/lib dir.
>>
>> This is what I want to have in the build.xml file:
>>
>>
>> <path name="some.path">
>> <pathelement location="some/local/dir/my.jar"/>
>> </path>
>>
>> <target name="mytarget">
>> <someCustomTask classpathref="some.path"/>
>> </target>
>>
>>
>> In this example the task someCustomTask needs to be able to have classes from
>> the path 'some.path' to be able to execute.
>>
>> I've been searching for examples or forum posts related to this but
everything
>> I've found isn't working. Does anyone have a good explanation of this is
> done
>> or are there some docs on this?
>>
>> Thanks in advance,
>>
>> Jon
>>
>>
>>
>
>
>
> --
> Wolfgang Häfelinger
> häfelinger IT - Applied Software Architecture
> http://www.haefelinger.it
> +31 648 27 61 59
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How to reference elements in custom task
Posted by Peter Reilly <pe...@gmail.com>.
There is nothing in ant that would do that (it was
planned at one stage).
In any case, it is not good practice to place
any extra jars into $ANT_HOME/lib, as this
makes reproducible builds difficult.
The ant-classloader task
http://enitsys.sourceforge.net/ant-classloadertask/ (written by
Rainer Noack) will
solve your problem, but at the "cost" of an extra jar.
Peter
On Mon, Mar 14, 2011 at 5:56 PM, Jon Svede <js...@yahoo.com> wrote:
> Wolfgang,
>
> Thanks for the reply.
>
> So originally I had my tasks working by defining a <path> entry that included my
> tasks and their dependencies. This worked fine without me having to do anything
> other than define <taskdef> entries in my build file.
>
> Then I was asked to make it so that my tasks could be put into the $ANT_HOME/lib
> dir but be able to define the dependencies in the build.xml. This did not work.
> My tasks would be found, but the dependencies were not. I am guessing it's
> parentage thing: my classes are higher in the classloader parentage than it's
> dependencies. I then tested this by adding all the classes my tasks depend on
> to my jar file in the $ANT_HOME/lib - that worked too, but it failed when I
> added classes that implement my interfaces. In this case, I think it is again
> some sort of parentage issue.
>
> My specific use case is as follows:
>
> I have a set of ant tasks that depend on Apache POI for spreadsheet testing. I
> do not want to package the POI classes into my jar. Secondarily, my jar file of
> tasks defines an interface for users to implement; those implementations can be
> given to my ant tasks for execution.
>
> I thought, perhaps incorrectly, that if my tasks could access the path element
> and then "inject" those references into the execution environment I'd be able to
> move forward. Am I mistaken?
>
> Most of what I found either didn't apply or I didn't understand. What I did
> find outside of that didn't seem to help. I found a reference to a Classloader
> task written by Peter Reilly but this is again an external task. I have been
> under the assumption that I would be able to resolve my issue with the core ant
> tasks rather than requiring additional non-core jars.
>
> Does that give you more insight into my problem? It's entirely possible that
> what I want to do isn't feasible but that is what I am basically asking: can I
> do this as I've described or is there another, more preferable way to accomplish
> this?
>
> Sincerely,
>
> Jon
>
>
>
>
> ________________________________
> From: wolfgang haefelinger <wh...@gmail.com>
> To: Ant Users List <us...@ant.apache.org>
> Sent: Mon, March 14, 2011 11:21:57 AM
> Subject: Re: How to reference <path> elements in custom task
>
> Jon,
>
>> <someCustomTask classpathref="some.path"/>
>
> This attribute of yours, "classpathref" is not a standard attribute:
> http://ant.apache.org/manual/Tasks/common.html
>
>> I've been searching for examples or forum posts related to this but everything
>> I've found isn't working.
>
> How about sharing what you've found and what exactly is not working?
>
> // Wolfgang
>
> On Mon, Mar 14, 2011 at 5:50 PM, Jon Svede <js...@yahoo.com> wrote:
>> Hi,
>>
>> I have a set of custom tasks that need to be able to load dependencies from
>> <path> element. In my case my tasks may be defined in <taskdef> declarations
>>or
>> via adding the jar file to the $ANT_HOME/lib dir.
>>
>> This is what I want to have in the build.xml file:
>>
>>
>> <path name="some.path">
>> <pathelement location="some/local/dir/my.jar"/>
>> </path>
>>
>> <target name="mytarget">
>> <someCustomTask classpathref="some.path"/>
>> </target>
>>
>>
>> In this example the task someCustomTask needs to be able to have classes from
>> the path 'some.path' to be able to execute.
>>
>> I've been searching for examples or forum posts related to this but everything
>> I've found isn't working. Does anyone have a good explanation of this is
> done
>> or are there some docs on this?
>>
>> Thanks in advance,
>>
>> Jon
>>
>>
>>
>
>
>
> --
> Wolfgang Häfelinger
> häfelinger IT - Applied Software Architecture
> http://www.haefelinger.it
> +31 648 27 61 59
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How to reference elements in custom task
Posted by Jon Svede <js...@yahoo.com>.
Wolfgang,
Thanks for the reply.
So originally I had my tasks working by defining a <path> entry that included my
tasks and their dependencies. This worked fine without me having to do anything
other than define <taskdef> entries in my build file.
Then I was asked to make it so that my tasks could be put into the $ANT_HOME/lib
dir but be able to define the dependencies in the build.xml. This did not work.
My tasks would be found, but the dependencies were not. I am guessing it's
parentage thing: my classes are higher in the classloader parentage than it's
dependencies. I then tested this by adding all the classes my tasks depend on
to my jar file in the $ANT_HOME/lib - that worked too, but it failed when I
added classes that implement my interfaces. In this case, I think it is again
some sort of parentage issue.
My specific use case is as follows:
I have a set of ant tasks that depend on Apache POI for spreadsheet testing. I
do not want to package the POI classes into my jar. Secondarily, my jar file of
tasks defines an interface for users to implement; those implementations can be
given to my ant tasks for execution.
I thought, perhaps incorrectly, that if my tasks could access the path element
and then "inject" those references into the execution environment I'd be able to
move forward. Am I mistaken?
Most of what I found either didn't apply or I didn't understand. What I did
find outside of that didn't seem to help. I found a reference to a Classloader
task written by Peter Reilly but this is again an external task. I have been
under the assumption that I would be able to resolve my issue with the core ant
tasks rather than requiring additional non-core jars.
Does that give you more insight into my problem? It's entirely possible that
what I want to do isn't feasible but that is what I am basically asking: can I
do this as I've described or is there another, more preferable way to accomplish
this?
Sincerely,
Jon
________________________________
From: wolfgang haefelinger <wh...@gmail.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Mon, March 14, 2011 11:21:57 AM
Subject: Re: How to reference <path> elements in custom task
Jon,
> <someCustomTask classpathref="some.path"/>
This attribute of yours, "classpathref" is not a standard attribute:
http://ant.apache.org/manual/Tasks/common.html
> I've been searching for examples or forum posts related to this but everything
> I've found isn't working.
How about sharing what you've found and what exactly is not working?
// Wolfgang
On Mon, Mar 14, 2011 at 5:50 PM, Jon Svede <js...@yahoo.com> wrote:
> Hi,
>
> I have a set of custom tasks that need to be able to load dependencies from
> <path> element. In my case my tasks may be defined in <taskdef> declarations
>or
> via adding the jar file to the $ANT_HOME/lib dir.
>
> This is what I want to have in the build.xml file:
>
>
> <path name="some.path">
> <pathelement location="some/local/dir/my.jar"/>
> </path>
>
> <target name="mytarget">
> <someCustomTask classpathref="some.path"/>
> </target>
>
>
> In this example the task someCustomTask needs to be able to have classes from
> the path 'some.path' to be able to execute.
>
> I've been searching for examples or forum posts related to this but everything
> I've found isn't working. Does anyone have a good explanation of this is
done
> or are there some docs on this?
>
> Thanks in advance,
>
> Jon
>
>
>
--
Wolfgang Häfelinger
häfelinger IT - Applied Software Architecture
http://www.haefelinger.it
+31 648 27 61 59
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How to reference elements in custom task
Posted by wolfgang haefelinger <wh...@gmail.com>.
Jon,
> <someCustomTask classpathref="some.path"/>
This attribute of yours, "classpathref" is not a standard attribute:
http://ant.apache.org/manual/Tasks/common.html
> I've been searching for examples or forum posts related to this but everything
> I've found isn't working.
How about sharing what you've found and what exactly is not working?
// Wolfgang
On Mon, Mar 14, 2011 at 5:50 PM, Jon Svede <js...@yahoo.com> wrote:
> Hi,
>
> I have a set of custom tasks that need to be able to load dependencies from
> <path> element. In my case my tasks may be defined in <taskdef> declarations or
> via adding the jar file to the $ANT_HOME/lib dir.
>
> This is what I want to have in the build.xml file:
>
>
> <path name="some.path">
> <pathelement location="some/local/dir/my.jar"/>
> </path>
>
> <target name="mytarget">
> <someCustomTask classpathref="some.path"/>
> </target>
>
>
> In this example the task someCustomTask needs to be able to have classes from
> the path 'some.path' to be able to execute.
>
> I've been searching for examples or forum posts related to this but everything
> I've found isn't working. Does anyone have a good explanation of this is done
> or are there some docs on this?
>
> Thanks in advance,
>
> Jon
>
>
>
--
Wolfgang Häfelinger
häfelinger IT - Applied Software Architecture
http://www.haefelinger.it
+31 648 27 61 59
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org