ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Hoppe <>
Subject Ant Classloader - Context Classloader
Date Sun, 22 Jul 2001 20:07:51 GMT
Hi all,

I just wrote my first custom task (big compliment to the Ant architects - it
was really easy and straightforward!) and have some questions regarding

My task calls a class ("foo.class") which connects to an application server
and performs some bulk operations. Therefore I need to perform a JNDI lookup
to the server within foo. My task class is in the Ant lib directory and
included by a taskdef. If I include foo into the jar I have the following

- foo is in the ant library classpath / system classpath
- The JNDI InitialContextfactory of my application server needs to be in the
same classpath as well. If it's in a nested classpath element it  won't be
found from the classloader which loaded foo as that classloader is higher in
the hierarchy
- Therefore I'd need to put all application server classes into the system
classpath what I don't really like.

If I don't include foo into the jar but make my task use a nested classpath
attribute, I cannot directly reference foo as it is not in the system
classpath. I need to perform some heavy reflection to create an instance.
This works fine, but I wonder if there is a nicer approach.

If foo is loaded from the nested classpath element, further classloads from
within this class are performed by the Ant classloader which is to be
expected. What I don't understand is why the Ant classloader is not the
context classloader as well. Although I have my application server classes
in the nested classpath element, I have to set the context classloader
manually by calling


before I create the InitialContext within foo.

I did not find anything about this point in the mail-archive and I'm
wondering if this is an intended behaviour. It would be nice if someone
could put some light onto this.

Thanks in advance,


<sitewaerts> GmbH
Hebelstra├če 15
D-76131 Karlsruhe

Tel: +49 (721) 920 918 0
Fax: +49 (721) 920 918 29

View raw message