• Post Reply Bookmark Topic Watch Topic
  • New Topic

listing resources on classloader  RSS feed

 
Don Hill
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know if there is anyway besides using java.util.jar to get all the contents on the classloader for a package, for example if I had a 3 jars with entries that were in the same package /mypackage but diff contents accross the jars, I know I can get them if I know the names before hand using cl.getResourceAsStream() but I am looking for a more dynamic way to get all the entries that are on the classloader for a predefined package.
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever find a solution to this. I too wouldd be interested in the answer.

I've done such things as iterating through the classpath and getting all the class files in the those directories and jar files, but I can't believe that this is the best way.

Ryan
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two problems trying to do this using the ClassLoader. Firstly the ClassLoader only knows about a Class when it gets loaded - if you don't load a class it would never show up.

Secondly the ClassLoader doesn't make this information public. You can use reflection tricks to work around this in some cases, but then your solution is a hack and would probably be unstable.

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!