James Carman, President<br />Carman Consulting, Inc.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Ernest Friedman-Hill:
Hi,
Welcome to JavaRanch!
In the most general case, this is complicated. For example, a custom class loader might be installed, and it may not be possible to find out what classpath that custom class loader will search.
But despite what James says, if the standard class loader is in place, then doing what you want is relatively straightforward. The standard classloader uses the system property java.class.path to hold the classpath. So you can simply get the value of this property, split it into tokens using java.io.File.pathSeparator, and then, for each token:
1) If it's a directory, use the "listFiles" method of the java.io.File class to search for .class files, load them using Class.forName(), and then check the Class object for the interfaces it implements; or
2) If it's a JAR file, then use the java.util.zip package to open the file, search for .class file entries, and again, load the classes and ask each Class for the interfaces it implements.
This might sound like a lot of work, but it's really not so bad. The more you know about the structure of your plugins (always in a JAR, never in a JAR, etc) the easier you can make it.
James Carman, President<br />Carman Consulting, Inc.
Originally posted by James Carman:
Ahh, I was not aware of that. However, I thought they wanted a purely API-based approach. Which "standard classloader" are you talking about, so that I may inspect the code to learn more?
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Juan Fco. S.:
I gave a try to the "META-INF/plugin.xml (getResources())" solution, and it worked very well. Now I only have to put my_plugin.jar in the classpath and everything is automated.
Thanks a lot.
James Carman, President<br />Carman Consulting, Inc.
BWA HA HA HA HA HA HA! Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|