Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Fail to Use Custom ClassLoader
Alec Lee
Ranch Hand
Posts: 569
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I wrote my custom classloader but I have problem asking my class to use it. Here is my
test
code
package org.lyl.test; import org.lyl.attach.CustomLoader; public class ClassLdrTest { public static void main(String[] args) throws Exception { System.out.println("system class loader:" + ClassLoader.getSystemClassLoader().getClass().getName()); System.out.println("system class loader:" + ClassLoader.getSystemClassLoader().getParent().getClass().getName()); System.out.println("system class loader:" + ClassLoader.getSystemClassLoader().getParent().getParent()); CustomLoader ldr = new CustomLoader(); Class.forName("org.lyl.test.Dummy",true,ldr).newInstance(); } } === package org.lyl.test; public class Dummy { public Dummy() { System.out.println("my class loader:" + this.getClass().getClassLoader().getClass().getName()); } } === when executed: system class loader:sun.misc.Launcher$AppClassLoader system class loader:sun.misc.Launcher$ExtClassLoader system class loader:null my class loader:sun.misc.Launcher$AppClassLoader
It is always the system class loader get used (sun.misc.Launcher$AppClassLoader
) when I load the org.lyl.test.Dummy class? What mistake did I make?
Rob Spoor
Sheriff
Posts: 22783
131
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If the Dummy class is on the class path, the system class loader will (almost?) always load it.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Classloader issues
How can I set current class loader
Setting new default class loader
Class.forName() and .class not working but .getClass() works
Loading Classes in at Runtime - NoClassDefFound
More...