The Artima Developer Community
Sponsored Link

Java Answers Forum
Custom ClassLoader & getClassLoader

1 reply on 1 page. Most recent reply: Aug 21, 2003 1:21 AM by Alex S

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Custom ClassLoader & getClassLoader Posted: Aug 20, 2003 6:00 AM
Reply to this message Reply
Advertisement
I'm trying to write a custom classloader which is used not only for all of the classes it loads but also all of the classes that the loaded classes load.

According to the docs, when a class loader loads a class it is set as the loader for the class. When you call Class.getClassLoader it should be returned. That doesn't seem to be happening for me. I get the primordial class loader. I can only suppose that I'd have to lick this problem before dealing with the classes the loaded class loads.

When I look at the source, I see that Class.getClassLoader delegates to a native method. I can only assume that the JVM is setting it.

Anyone see a path towards where I am going?

Thanks,

Michael


Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: Custom ClassLoader & getClassLoader Posted: Aug 21, 2003 1:21 AM
Reply to this message Reply
Create a custom class loader (public class MyClassLoader extends ClassLoader). Then do:
myClassLoader.loadClass("ClassToLoad")
Your class loader should read the bytecode and then call defineClass() (from the ClassLoader class).
From now on, any class referenced by class ClassToLoad will come to your class loader to load. But if you delegate the loading to your parent class loader (let's say for JFrame), then don't expect to catch the loading calls for the classes refered by JFrame.

The idea is that if a class C is loaded by a class loader L, then the JVM will ask L to load any class referenced by C. Of course, L could delegate the loading to its parent class loader. So, be careful when writing your custom class loader.

Flat View: This topic has 1 reply on 1 page
Topic: readLine() Previous Topic   Next Topic Topic: java on a web server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use