🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1811

Re: (How to) Change the *default* classloader?

#1811
From: Holger Stratmann
Date: Mon, 17 Sep 2001 09:32
106 lines
4978 bytes
Hi Nabin,

thanks for the hint, but unfortunately, setContextClassLoader() doesn't "do"
anything!
All it does is provide a classloader that threads CAN then access (by calling
getContextClassLoader()). It does not even change the behavior of
Class.forName, much less what I wanted to do :-((

Nabin Thomas wrote:

> 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
>
> ***************************************************
>  ***********************************

--

                       \\///
                      ('O O')
--------------------ooO-(_)-Ooo--------------------
Holger Stratmann
mailto:Holger@cheerful.com
---------------------------------------------------
Technical Details
Message-ID: <3BA5C339.C93D4C2D@cheerful.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews
References: <3B9F5750.AFC14A93@cheerful.com> <3BA21369.103CC668@hotmail.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-17 02:33:39 PST
Message-ID: <3BA5C339.C93D4C2D@cheerful.com>
Date: Mon, 17 Sep 2001 11:32:41 +0200
From: Holger Stratmann <Holger@cheerful.com>
X-Mailer: Mozilla 4.72 [en] (WinNT; 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> <3BA21369.103CC668@hotmail.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 213.61.105.117
X-Trace: dnews 1000719187 213.61.105.117 (17 Sep 2001 02:33:07 -0700)
Lines: 108
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews