Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interogating jars for specific classes

 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to write a method that goes around my classpath finding jars (that bit done and sorted using a url classloader).
then i want to interogate the jars hunting for any look and feels (so any class extending LookAndFeel)
here is my current attempt:






what am i supposed to do next?
i hope i have given enough information

edit:
Forgot to add this code has been copied from somewhere else in the application, but that insited the class name it was hunting for finished with CustomerAddOn, so i can't nick the rest of it. I considered reflection but that sounded far too heavyweight.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that the class you are trying to load is not present in the ClassLoader represented by 'currentClassLoader'. If the currentClassLoader is an instance of URLClassLoader you should first add the URL to the JAR before trying to load the class. Alternatively, if you already added the JAR to a ClassLoader, user that one to load the class file.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't forget that any libraries needed by those classes need to be loaded by that class loader as well. So make sure that either the URLClassLoader has loaded them, or they are loaded by a class loader which you then use to construct the URLClassLoader.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i have solved my own problem with:


but now i am 1 worried about rob's comment and 2 getting: java.lang.OutOfMemoryError: PermGen space.

I have decided to only load look and feels that end with LookAndFeel thus stopping me loading 12723 classes before running out of permgen memory


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic