Article View: borland.public.jbuilder.java.api
Article #1801(How to) Change the *default* classloader?
From: Holger Stratmann
Date: Wed, 12 Sep 2001 12:38
Date: Wed, 12 Sep 2001 12:38
48 lines
3106 bytes
3106 bytes
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
---------------------------------------------------
Technical Details
Message-ID:
<3B9F5750.AFC14A93@cheerful.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,2ebd18d9e54d1eb,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-09-12 05:45:27 PST Message-ID: <3B9F5750.AFC14A93@cheerful.com> Date: Wed, 12 Sep 2001 14:38:40 +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: (How to) Change the *default* classloader? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.61.105.117 X-Trace: dnews 1000298312 213.61.105.117 (12 Sep 2001 05:38:32 -0700) Lines: 50 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews