Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Load class from Jar file 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 "Load class from Jar file" Watch "Load class from Jar file" New topic
Author

Load class from Jar file

Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
I have my own class loader, and I wish to load a class from a Jar file.
How do I do it?
I have overridden the

How do I read the class from the Jar file
Thanks!


Don't be shy, be quiet!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Do you need to write your own ClassLoader? You can use a URLClassLoader to load the class from a JAR file, unless you need some specific behaviour not provided by the existing ClassLoaders.
Even if you do, you can extend the URLClassLoader, override the bits you need, then delegate the 'loading of classes from jar files' bit to the parent.
The following code uses aURLClassLoader to load a class from a JAR file.

Note you'll have to play with the dir1/my.jar part to get it working correctly.
Dave
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
Thanx!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Load class from Jar file
 
Similar Threads
security problem
Sending class file through a network
Is it the right way?
URLyBird 1.2.1 - validate or not validate the data
Cannot Find "Properties" File