File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Loading classes from a Jar file problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Loading classes from a Jar file problem" Watch "Loading classes from a Jar file problem" New topic
Author

Loading classes from a Jar file problem

Josh Lam
Greenhorn

Joined: Feb 16, 2000
Posts: 19
I am trying to load classes from a jar file using URLClassLoader
using the following code:
void loadAClass(String className){
URL aUrl = new URL("jar:file:/D:/App/ajar.jar!/");
URL[] urls = {aUrl};
URLClassLoader jarClassLoader = new URLCLassLoader(urls);
Class c = jarClassLoader.loadClass(className);
}
Suppose in the jar file I have a class called X.class and the fully qualified name is: A.B.X.class
What should the format of 'className' be when I invoke loadClass()? Should it be A.B.X.class or A/B/X.class. Either one I tried I get java.lang.ClassNotFoundException.
What am I doing wrong?
Josh Lam
Greenhorn

Joined: Feb 16, 2000
Posts: 19
I am going to answer my own question:
The answer is:
loadAClass("A.B.X");
Note: the '.class' suffix is not needed.
 
wood burning stoves
 
subject: Loading classes from a Jar file problem
 
Similar Threads
Regarding ClassLoader concept
Loading POJO object without loading library first
URLClassLoader locking the jars
Loading Classes From A Jar File Problem
loading JDBC driver from a Jar (not in classpath)