Article View: borland.public.jbuilder.java.api
Article #1809Re: (How to) Change the *default* classloader?
From: Nabin Thomas
Date: Fri, 14 Sep 2001 14:25
Date: Fri, 14 Sep 2001 14:25
87 lines
4256 bytes
4256 bytes
The java.land.Thread class has some method to set the default classloader
for that thread.
Setting the default classloader of the main thread may probably work
May be like
class Fooo{
public static void main (String args[]){
URLClassLoader[] utls={ "file://c:/custompath/tomclasses.jar" };
ClassLoader currentLoader=Thread.getContextClassLoader();
Thread.currentThread().setContextClassLoader(new
URLClassLoader(urls),currentLoader);
//................................
}
//......................
}
Holger Stratmann wrote:
> Hello everybody,
>
> I've just started experimenting with ClassLoaders and many things
> already work fine.
> My problem is: I would like my ClassLoader to ALWAYS get the FIRST shot
> at loading a class!
> Then if it doesn't find it or decides that it doesn't care about that
> class, it can call the "normal" system class loader.
>
> For you to understand what I'm doing:
> I want to reload the classes for certain packages during runtime. From
> what I've read so far, I need to dispose the ClassLoader that loaded the
> classes, in order to dispose the "Class"es.
> I do have a ClassLoader that does this. However, subsequent calls to
> "Class.forName(...)" always use the classloader that was used to load
> that class (the calling class).
>
> Example: (Problem specification)
> My class loader handles "com.me.myunloadablepackage". I use my
> ClassLoader to load/define a class in that package. Fine. One of those
> classes calls "Class.forName(...)". Still fine, calls MY ClassLoader.
> Then I use my classloader to load com.me.somepackage.someclass. My
> classloader looks at it and calls super (which loads via "normal" class
> loader). Now THIS new class doesn't know/care about my classloader at
> all and uses the standard loading mechanism for Class.forName(...).
>
> I know that I "could"/should get rid of normal
> 'Class.forName("classname");' calls, but I can't. I want to change the
> classloader for an existing application without adjusting 30 something
> source files (that's a rough estimate). Also, I don't want to add this
> to the programming guidelines ("don't call Class.forName()" ??!).
>
> I couldn't find "getClass().SETSystemClassLoader()" *g*
>
> Any ideas? Where's the missing piece of the puzzle?
>
> P.S.: I wouldn't want to load EVERY class myself (which would solve the
> problem!), because we have 45 jar-Files in our path. I'm kind of afraid
> my own classloader would deliver *ehem* - a little less performance than
> the "normal" one.
> --
>
> \\///
> ('O O')
> --------------------ooO-(_)-Ooo--------------------
> Holger Stratmann
> mailto:Holger@cheerful.com
> ---------------------------------------------------
--
***********************************
***************************************************
******************* Web Card **********************
***************************************************
Name : Nabin Thomas
e-mail : nabinthomas.DONOTSPAM@hotmail.com
Web : http://nabin.topcities.com
http://nabinthomas.net
Feel free to contact me thru e-mail or MSN Mssenger
if required but DONOT SPAM
***************************************************
***********************************
Technical Details
Message-ID:
<3BA21369.103CC668@hotmail.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!skynet.be!skynet.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3B9F5750.AFC14A93@cheerful.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,2ebd18d9e54d1eb X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-09-15 19:04:07 PST Message-ID: <3BA21369.103CC668@hotmail.com> Date: Fri, 14 Sep 2001 19:55:45 +0530 From: Nabin Thomas <nabinthomas.DONOTSPAM@hotmail.com> X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api Subject: Re: (How to) Change the *default* classloader? References: <3B9F5750.AFC14A93@cheerful.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 202.9.167.113 X-Trace: dnews 1000605114 202.9.167.113 (15 Sep 2001 18:51:54 -0700) Lines: 91 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!skynet.be!skynet.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews