Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load class from Jar file

 
Azriel Abramovich
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic