views:

39

answers:

1

I have a custom class loader which extends from a URLClassLoader. I added a .class file to the urlpath using addURL(); but when i do a class.forname() using this loader i get a ClassNotFoundException. However, if i create a jar and add the jar to the urlpath, i do not get any exception.

Using addURL(), can we add a .class file or a directory?? Can someone confirm this because it does not work for me?

+1  A: 

addURL's argument should point to the directory containing the root package of your .class, not the file itself.

cadrian
For a Sun JVM this is true, but interestingly, the javadoc is so vague and the actual implementation is hidden in the `sun.misc` package, so it may not hold for all JVMs.
Ash