ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject ant and classloading
Date Mon, 16 Oct 2006 03:40:23 GMT

I'm not sure this is 100% an Ant question, but it is within the context of Ant.

In my Ant task, I'm loading up a class using Class.forName() and pass 
in a classloader that I would have expected to be assigned as the 
classloader for the class.  That doesn't seem to be the case.  Here's 
what I'm doing..

AntClassLoader customLoader = new 
AntClassLoader(getClass().getClassLoader(), true);

Class clazz = Class.forName(clazzName, true, customLoader);


The DTD resource is found in the first case using the custom 
classloader where the user configured the resourcePath attribute of 
the task, but in the second case when I use the classloader of the 
class that I just loaded by passing in the custom classloader I just 
get "null".  The point of this is that the class I am loading needs 
to look up user-defined resources on the classpath.  With the 
System.out lines, I am just testing what my loaded class needs to do 
further down the line.

Shouldn't the classloader of the class I just loaded be a reference 
to that which I passed into Class.forName()?  This is probably more 
of a general classloading question than an Ant question, but I'm 
guessing others have had to deal with that here.  I must be making a 
bad assumption, but it seems like something like this should be possible.

My only workaround right now is to add the extra classpath 
information to the Task definition classpath.  However, that is not 
intuitive for task users and a pretty ugly hack.  Is there any way to 
do this?  I've run into and solved many classloading issues in the 
past, but I've never had to deal with this specifically.  I have to 
imagine someone has solved this problem already.  Care to share the solution?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message