Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@jakarta.apache.org Received: (qmail 44035 invoked by uid 500); 22 Jul 2001 20:07:15 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: ant-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 44025 invoked from network); 22 Jul 2001 20:07:14 -0000 Message-ID: <903A7281CDB7D4118A5000500450BB08382D9A@samoa.sitewaerts> From: Daniel Hoppe To: "'ant-dev@jakarta.apache.org'" Subject: Ant Classloader - Context Classloader Date: Sun, 22 Jul 2001 22:07:51 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N 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 classloading. 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 situation: - 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 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoa= der( )); 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, Daniel <<<<<<<<<<<<<<<<<<<<<<<<<<< GmbH Hebelstra=DFe 15 D-76131 Karlsruhe Tel: +49 (721) 920 918 0 Fax: +49 (721) 920 918 29 http://www.sitewaerts.de >>>>>>>>>>>>>>>>>>>>>>>>>>>