ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam R. B. Jack" <aj...@trysybase.com>
Subject Re: Baffled in classloader land
Date Sun, 02 Nov 2003 16:37:37 GMT
> I've just had a short look into commons-discovery.  They search the
> thread context classloader and getClass().getClassloader().  At least
> that's my understanding of ServiceDiscoveryTask.  So maybe you should
> fall back to your class's classloader if a resource cannot be loaded
> via the context classloader.

Sorry to be joining this late, but this is something that has been biting me
recently. I write code that uses classloading (for resources, for optional
class loading, for whatever) and I want it to run inside Ant, inside
Eclipse, and inside other environments. I "borrowed" the code that
CommonsLogging was using, thinking it was likely "correct" -- and it was
using getContextClassloader also.Sadly, I was failing miserably in
Eclipse-land although not noticing too much of a problem in ant land. Maybe
I was lucky and in my tests, my ant classpath was pretty much the same as my
JVM one. I suspect it is this.

Sadly I've come to the conclusion that using getContextClassLoader is
seriously flawed. Maybe it works ok for webapps, but many other tooling
environments just don't have that simple a time. Within eclipse (for
example) the calling thread may not be with the 'context' (say a Java
project) that one wants. As a corrolary, I have no idea how Ant within
Eclipse will cope!

Sadly this is a mess, and one I don't have a real answer to -- I just wanted
to add my level of misery to the pile. ;-) I've taken to loading resources
with a classloader from the class related to the resources, and that helps,
but is imperfect. I am trying to get more "hand on" over my classloader
usage in my code, in the hope I can do the right things in the right
environments, but for certain -- getContextClassLoader is not it.

Maybe ant tasks need a getClassloader() method, maybe all project entities
need one also. I wish there was a simple answer to this, and I've tried
reading information on the web [and all they tell you is how to write a
classloader, not how to survive classloader hell.] Maybe there is a
commons-classloader out of all this. ;-)

regards,

Adam


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


Mime
View raw message