Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 57978 invoked from network); 16 Oct 2006 09:20:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Oct 2006 09:20:43 -0000 Received: (qmail 12228 invoked by uid 500); 16 Oct 2006 09:20:38 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 12196 invoked by uid 500); 16 Oct 2006 09:20:38 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 12185 invoked by uid 99); 16 Oct 2006 09:20:38 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Oct 2006 02:20:38 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of peter.kitt.reilly@gmail.com designates 64.233.182.188 as permitted sender) Received: from [64.233.182.188] (HELO nf-out-0910.google.com) (64.233.182.188) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Oct 2006 02:20:37 -0700 Received: by nf-out-0910.google.com with SMTP id x29so2162126nfb for ; Mon, 16 Oct 2006 02:20:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XkhP1LEezZXV5PerUu36tDI+LjRw0ZxufBEyco9X1qiF/751qCa8FVYgp8zpSIIPHDTmE8PhMevyQg+SvAJ5osQT3WWBuOs39ECtW7/TgvYEcEsXv1nHY89aHUnp/G/RsqfXapkbItP5ed/WNMnggf7gyQGz97ewU6XUnoFoUT0= Received: by 10.48.210.20 with SMTP id i20mr11768078nfg; Mon, 16 Oct 2006 02:20:15 -0700 (PDT) Received: by 10.49.90.10 with HTTP; Mon, 16 Oct 2006 02:20:15 -0700 (PDT) Message-ID: Date: Mon, 16 Oct 2006 10:20:15 +0100 From: "Peter Reilly" To: "Ant Users List" Subject: Re: ant and classloading In-Reply-To: <7.0.1.0.0.20061015221533.0485b050@syntegra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7.0.1.0.0.20061015221533.0485b050@syntegra.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On 10/16/06, Jacob Kjome wrote: > > 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); > customLoader.setClassPath(getResourcePath()); > > Class clazz = Class.forName(clazzName, true, customLoader); > > System.out.println(customLoader.getResource("org/myorganization/resources/my.dtd")); > System.out.println(clazz.getClassLoader().getResource("org/myorganization/resources/my.dtd")); > > > 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()? No, Java uses a delegated classloader model. Normally, classloaders search up the hierarchy, starting at the base classloader to load a class. The reason for this is that classes are not the same unless they are loaded from the same classloader. To take a simple case one would want java.lang.Object to be the same no matter how it is loaded. > 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? > > > Jake > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > For additional commands, e-mail: user-help@ant.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org