You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Hoying, Ken" <KH...@tiaa-cref.org> on 2005/09/16 17:52:38 UTC

Class loader problem

I am having a class loading problem with Ant.  We have a standard Ant distribution which includes a jar file with a v1.1 of a task in the Ant distribution's lib directory.  However, our project is still using the 1.0 version of this task.  I have included the jar with the 1.0 version of the task in my build lib and have set a path to that build lib.  I have referenced that path in classpathref attribute of the taskdef.  However, no matter what I seem to do, Ant always seems to load the taskdef from the Ant lib jar instead of from the build lib jar.

Any help would be greatly appreciated.

Thank you,
Ken Hoying




**************************************************************
This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, please contact sender immediately by reply e-mail and destroy all copies.  You are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.
TIAA-CREF
**************************************************************


RE: Class loader problem

Posted by Rainer Noack <ra...@noacks.net>.
Hi Ken,
If you use <taskdef/> with a classpath, the task will be loaded by a 
newly created classloader that uses the project classloader as delegation
classloader.
(if you're using the distributed launch scripts, the project classloader is
a delegation
child of the System classloader). 
The distributed task - as well as the common Ant classes - are loaded by the
project
classloader. If the delegation child for your (older) task looks for the
task's class,
it finds the newer version (with the same classname) in it's delegation
parent which takes 
precedence over the class in the delegation child.

I don't have a "clean" out-of-the-box solution for your problem but you have
some options to play with. 
Their success depends mostly on your task dependencies. In every case, you
should make sure
that the jar with the old version of your task don't affect other tasks.

1. try the - highly deprecated and not longer documented - taskdef
attribute: reverseLoader="true"

2. inject your jar in project classloader's classpath prior to the jars in
$ANT_HOME/lib 
   by setting CLASSPATH=my_older_jar env variable
   (maybe putting into $USER_HOME/.ant/lib or using the -lib option might
have the same effect but i'm not sure)

3. define your (old) build jar as a system extension via
ANT_OPTS="-Djava.ext.dirs=path_to_dir"

To get more information about the classloader stuff in your build, you might
want to test <classloaderreport>
which is available under http://jtools.org/ant-classloadertask/
(It is proposed as a CoreTask in Ant 1.7.)

There you will also find <classloader> that allows you one more dirty
solution:

4. add your jar to the system-classloader's classpath via the <classloader>
task.

Hope that helps a little bit
Cheers
Rainer

> -----Original Message-----
> From: Hoying, Ken [mailto:KHoying@tiaa-cref.org] 
> Sent: Friday, September 16, 2005 5:53 PM
> To: user@ant.apache.org
> Subject: Class loader problem
> 
> 
> 
> I am having a class loading problem with Ant.  We have a 
> standard Ant distribution which includes a jar file with a 
> v1.1 of a task in the Ant distribution's lib directory.  
> However, our project is still using the 1.0 version of this 
> task.  I have included the jar with the 1.0 version of the 
> task in my build lib and have set a path to that build lib.  
> I have referenced that path in classpathref attribute of the 
> taskdef.  However, no matter what I seem to do, Ant always 
> seems to load the taskdef from the Ant lib jar instead of 
> from the build lib jar.
> 
> Any help would be greatly appreciated.
> 
> Thank you,
> Ken Hoying
> 
> 
> 
> 
> **************************************************************
> This message, including any attachments, contains 
> confidential information intended for a specific individual 
> and purpose, and is protected by law.  If you are not the 
> intended recipient, please contact sender immediately by 
> reply e-mail and destroy all copies.  You are hereby notified 
> that any disclosure, copying, or distribution of this 
> message, or the taking of any action based on it, is strictly 
> prohibited. TIAA-CREF
> **************************************************************
> 
> 


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