You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Allan Lewis <al...@gmail.com> on 2011/02/19 16:17:20 UTC

Accessing classes in a path from a custom task

I'm working on a custom ant task, and want to create a class based on
classname provided to the task.  I've made a path available to the task, but
can't quite figure out how to make those classes available to the task, so I
wind up getting a java.lang.ClassNotFoundException when trying to create the
class.

 

In other words, given the following:

 

<path id="my.path">

<fileset dir="lib" includes="*.jar"/>

</path>

 

<path id="my.runtime.path">

<fileset dir="lib-runtime" includes="*.jar"/>

</path>

 

<typedef name="mytask" classname="com.mytask.MyTask"
classpathref="my.path"/>

 

< mytask classpathref="my.runtime.path" classname="com.foo.Bar"/>

 

What has to happen in order to get 'com.foo.Bar' available to my task at
runtime?


Re: Accessing classes in a path from a custom task

Posted by Matt Benson <gu...@gmail.com>.
On Sat, Feb 19, 2011 at 9:17 AM, Allan Lewis <al...@gmail.com>wrote:

> I'm working on a custom ant task, and want to create a class based on
> classname provided to the task.  I've made a path available to the task,
> but
> can't quite figure out how to make those classes available to the task, so
> I
> wind up getting a java.lang.ClassNotFoundException when trying to create
> the
> class.
>
>
>
> In other words, given the following:
>
>
>
> <path id="my.path">
>
> <fileset dir="lib" includes="*.jar"/>
>
> </path>
>
>
>
> <path id="my.runtime.path">
>
> <fileset dir="lib-runtime" includes="*.jar"/>
>
> </path>
>
>
>
> <typedef name="mytask" classname="com.mytask.MyTask"
> classpathref="my.path"/>
>
>
>
> < mytask classpathref="my.runtime.path" classname="com.foo.Bar"/>
>
>
>
> What has to happen in order to get 'com.foo.Bar' available to my task at
> runtime?
>
> You might find org.apache.tools.ant.AntClassLoader useful for your
purposes.

HTH,
Matt