You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Johannes Rieken <jo...@riejo.de> on 2005/10/27 21:10:53 UTC

Custom ant task and resources

Hi everyone!

I 've written a custom ant task which I deploy as a jar file. This jar file 
contains another jar file which is read during task execution. 
I'm using the static method "ClassLoader.getSystemResource(String):URL" to 
access resources in jar file which usually works fine. 
However calling it form my ant task doesn't work. (null is returned, although 
the resource exists and the path is correct)
Does anyone know what I am doing wrong? I've tried 
"MyTask.class.getResource(String):URL" but had no success.

Cheers, Johannes

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


Re: Custom ant task and resources

Posted by Dale Anson <da...@grafidog.com>.
Johannes,

I've written a classloader that handles that specific situation. You can 
view the source at:

http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/launcher/SubJarClassLoader.java?rev=1.1&view=markup

This code is distributed with Antelope, the source is available at 
http://antelope.tigris.org.

Hope this helps!

Dale



Antoine Levy-Lambert wrote:

>Johannes Rieken wrote:
>
>  
>
>>Hi everyone!
>>
>>I 've written a custom ant task which I deploy as a jar file. This jar file 
>>contains another jar file which is read during task execution. 
>>I'm using the static method "ClassLoader.getSystemResource(String):URL" to 
>>access resources in jar file which usually works fine. 
>>However calling it form my ant task doesn't work. (null is returned, although 
>>the resource exists and the path is correct)
>>Does anyone know what I am doing wrong? I've tried 
>>"MyTask.class.getResource(String):URL" but had no success.
>>
>> 
>>
>>    
>>
>Hello Johannes,
>
>you are not doing anything wrong, but the jar file which is included
>(nested) into the jar containing the task will not be loaded by the
>AntClassLoader. This class loader only loads jars or zips existing
>on the filesystem, but cannot at the moment add to the class path a zip
>entry which happens to be a jar.
>
>So you would need to present the nested jar separately in the filesystem
>and put it in the classpath.
>
>Maybe other committers would know of better solutions though. :-)
>
>  
>
>>Cheers, Johannes
>>
>>
>> 
>>
>>    
>>
>
>Antoine
>
>---------------------------------------------------------------------
>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: Custom ant task and resources

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Johannes Rieken wrote:

>Hi everyone!
>
>I 've written a custom ant task which I deploy as a jar file. This jar file 
>contains another jar file which is read during task execution. 
>I'm using the static method "ClassLoader.getSystemResource(String):URL" to 
>access resources in jar file which usually works fine. 
>However calling it form my ant task doesn't work. (null is returned, although 
>the resource exists and the path is correct)
>Does anyone know what I am doing wrong? I've tried 
>"MyTask.class.getResource(String):URL" but had no success.
>
>  
>
Hello Johannes,

you are not doing anything wrong, but the jar file which is included
(nested) into the jar containing the task will not be loaded by the
AntClassLoader. This class loader only loads jars or zips existing
on the filesystem, but cannot at the moment add to the class path a zip
entry which happens to be a jar.

So you would need to present the nested jar separately in the filesystem
and put it in the classpath.

Maybe other committers would know of better solutions though. :-)

>Cheers, Johannes
>
>
>  
>

Antoine

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