Search code examples
javaurlclassloaderclassnotfoundexception

can a .class file be added to the urlpath of a URLClassLoader


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?


Solution

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