Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 19925 invoked from network); 25 Jan 2008 15:02:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jan 2008 15:02:20 -0000 Received: (qmail 79772 invoked by uid 500); 25 Jan 2008 15:02:05 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 79743 invoked by uid 500); 25 Jan 2008 15:02:05 -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 79732 invoked by uid 99); 25 Jan 2008 15:02:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Jan 2008 07:02:05 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of james.abley@gmail.com designates 64.233.182.186 as permitted sender) Received: from [64.233.182.186] (HELO nf-out-0910.google.com) (64.233.182.186) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Jan 2008 15:01:39 +0000 Received: by nf-out-0910.google.com with SMTP id d21so83205nfb.10 for ; Fri, 25 Jan 2008 07:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=jaW52DBag05NdGnL4MOWBzt0vjhyBcusDk0EypehZrs=; b=Iu49YcL/IeNdQLnK2AHnbABzhez9JYFTPZSCSTHWqHRkQtfa258D8JhuwfigQjYbkgr1Y0j+tQ8dPOHaW02kdnviRE2TIL8mI/mxwnvTkbQb+lfVIzR3PaGZT5VtCZhIrWB7L9PW5MYoEYj2dMuMgUyuDG5f4HO9ii+iarlRY04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P+el/vabBsPhlHBfcDi+HVXa4kkNIRvFgetGzLs8vBs9SAAaWzfaryz2r6F01y/k9IOBFQ2tUyzw/F/tSrxy8lvg0Hspyy48dL3TlPGuVKqi8ItQievX80Ai4xm8U/WUF6609lOUENw34OGYE7vzRxEp2Bls1bB5WjxW2+3Lpag= Received: by 10.78.205.7 with SMTP id c7mr3019300hug.29.1201273304537; Fri, 25 Jan 2008 07:01:44 -0800 (PST) Received: by 10.78.143.17 with HTTP; Fri, 25 Jan 2008 07:01:44 -0800 (PST) Message-ID: <23fce8e60801250701p46b8adc8mf798942c642803e6@mail.gmail.com> Date: Fri, 25 Jan 2008 15:01:44 +0000 From: "James Abley" To: "Ant Users List" Subject: Re: Looking for help with context classloader In-Reply-To: <7106C04C5CF9AA43B6B278F2C24FFF27D0E36F@AD1HFDEXC305.ad1.prod> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7106C04C5CF9AA43B6B278F2C24FFF27D0E36F@AD1HFDEXC305.ad1.prod> X-Virus-Checked: Checked by ClamAV on apache.org On 23/01/2008, Toomey, Kevin H (ATS, IT) wrote: > I'm writing a web application for among things, managing the building and deploying of applications, and I'm using Ant (1.7.0) as the engine for those pieces. The basic flow is: > > Project p = new Project(); > p.init(); > p.setUserProperty("ant.file", "common.xml") > ProjectHelper2 ph = new ProjectHelper2 > ph.parse(p, "common.xml"); > p.executeTarget("myTarget"); > > The common.xml file contains definitions for PVCS tasks I wrote to promote, label, get, etc. Those tasks get executed in targets found in common.xml. Those classes are in a jar file called myPVCS.jar. > > During development, I executed my code from a jar file, with any supporting jar files in my system class path (java -classpath myApp.jar;myPVCS.jar;ant.jar;log4j.jar;mail.jar.... myApp.myClass). Everything works fine. > > I then create my war file and place all the required jar files in the web-inf/lib folder. The application fails with a ClassNotFoundException during the call to the ProjectHelper2 parse method. It cannot find the class defined in my definition in common.xml. That class is in myPVCS.jar, which is in the web-inf/lib folder of my war file. If I update the snippet above with Class c = Class.forName("mypvcstask"), it finds it, so I know my war file structure is sound. > > From looking at Ant source code, javadoc, and postings I've found, it looks like PropertyHelper2 uses a thread context classloader which uses the system classloader (the one that started my weblogic instance to which my web app is deployed) as a parent. As a test, I put myPVCS.jar in the weblogic classpath and it did find the class. Naturally, I don't want to go that route because it breaks the whole "fully contained application in a war file" model I'm shooting for. > > I see references to LoaderUtils, AntClassLoader, and other things, but I can't figure out how to use them in my case. > Since the class shown above finds classes in my web-inf/lib folder, I believe what I want is the ability to do something like: > > ProjectHelper2 ph2 = new ProjectHelper2(); > ph2.setContextClassLoader(this.getClass().getClassLoader()); > ph2.parse(p, "common.xml"); > > What can I do, or am I just trying to do something that can't be done (in an efficient manner), and I need to rethink my approach. > > Thanks, > Kevin > > > > > ************************************************************************* > This communication, including attachments, is > for the exclusive use of addressee and may contain proprietary, > confidential and/or privileged information. If you are not the intended > recipient, any use, copying, disclosure, dissemination or distribution is > strictly prohibited. If you are not the intended recipient, please notify > the sender immediately by return e-mail, delete this communication and > destroy all copies. > ************************************************************************* > > Classloader fiddling is always fun, a bit like playing with shotguns. Probably not advisable unless you really know what you're doing. That said, if you have to mess with the classloader, have you tried setting the context classloader to a suitable classloader subclass which is aware of WEB-INF/lib and WEB-INF/classes, and then restoring the original classloader when you're done? Cheers, James --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org