You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jeremy Mawson <je...@gmail.com> on 2008/10/13 11:09:05 UTC

Access to custom task's classpath?

Hi

I have a custom task defined thus:

<taskdef resource="task.properties" classpathref="task.class.path"/>

The classpathref contains the jar which includes both my Task and a file 
resource. When I try to obtain the resource in the Task at runtime I'm 
unable to find it.

When I print out the java.class.path property in the task, it does not 
include the jar my Task is in!

The very task I'm running is not in the classpath. How is this the case? 
And more to the point, how can I obtain a reference to the task's jar 
during the task's runtime?

Thanks
Jem

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Access to custom task's classpath?

Posted by Jeremy Mawson <je...@gmail.com>.
Thank you Stefan, that helped a lot.

Jeremy


Stefan Bodewig wrote:
> On Mon, 13 Oct 2008, Jeremy Mawson <je...@gmail.com> wrote:
> 
>> I have a custom task defined thus:
>>
>> <taskdef resource="task.properties" classpathref="task.class.path"/>
>>
>> The classpathref contains the jar which includes both my Task and a
>> file resource. When I try to obtain the resource in the Task at
>> runtime I'm unable to find it.
> 
> You should be able to load it with MyTask.class.getResource().
> 
>> When I print out the java.class.path property in the task, it does
>> not include the jar my Task is in!
> 
> This property only reflect what the system classloader sees.  Your
> task has been loaded by a different classloader that has your custom
> jars in it as well.  You can get this ClassLoader via
> MyTask.class.getClassLoader().
> 
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Access to custom task's classpath?

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 13 Oct 2008, Jeremy Mawson <je...@gmail.com> wrote:

> I have a custom task defined thus:
> 
> <taskdef resource="task.properties" classpathref="task.class.path"/>
> 
> The classpathref contains the jar which includes both my Task and a
> file resource. When I try to obtain the resource in the Task at
> runtime I'm unable to find it.

You should be able to load it with MyTask.class.getResource().

> When I print out the java.class.path property in the task, it does
> not include the jar my Task is in!

This property only reflect what the system classloader sees.  Your
task has been loaded by a different classloader that has your custom
jars in it as well.  You can get this ClassLoader via
MyTask.class.getClassLoader().

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org