*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading Classes From A Jar File Problem
 
Similar Threads
Loading POJO object without loading library first
URLClassLoader locking the jars
Regarding ClassLoader concept
loading JDBC driver from a Jar (not in classpath)
Loading classes from a Jar file problem