File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Classloader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Classloader" Watch "Classloader" New topic


karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
hi everybody
im writing a classloader that loads the classbytes from a DB.
when i instantiate classes using this classloader, then i get java.lang.ClassCastException.
here is what i do: i overwrite the findClass method to load bytes from DB, then call defineClass and return this class. the bytes i retrieve from DB are correct (same as class file in file system)
is there anything else im supposed to do ?
what is definePackage for ? what are all the parameters in definePackage ?
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
whatever you have done is just fine. I don't think you need to be bothered about other methods in java.lang.ClassLoader.
did you try printing out the class name after loading it?
classObj.getName() --> what does it print?
has this class been already loaded by some other class loader(the System class loader?) before
And you are trying to load it again using your custom class loader.
The cast then tends to fail in such cases.
It w'd be nice if you could elaborate the problem a bit. We c'd all learn from it!
I agree. Here's the link:
subject: Classloader
It's not a secret anymore!