我想在预定义的目录中查找扩展 jar 并检查它们的清单。那些匹配的应该被加载,那些不匹配的应该被卸载。
Now, I can do it a primitive way - mandate that each extension pass the name of its bootstrapper on the command line and then for each jar found in the directory try and load any of the given bootstrapper types. Something like this:
java -jar myapp.jar --pluginDir=c:/a/b/c --exts="classA;classB;classC"
Then myapp would iterate over all the files inside the pluginDir
and try to load each of classA
, classB
or classC
. Once a classX
is successfully loaded, it is removed from the list. The search stops when either all the extensions are found and loaded or there are no more jars in the plugin dir.
A slightly more javaish approach seems to be writing something in the manifest of extension jars and check the manifest of each found jar.
Can anyone show a working code snippet of this approach or of anything better, if there is?
EDIT
A quote from the postgre JDBC driver README file (see https://stackoverflow.com/a/12480373/80002):
INSTALLING THE DRIVER
To install the driver, the postgresql.jar file has to be in the classpath.
ie: under LINUX/SOLARIS (the example here is my linux box):
export CLASSPATH=.:/usr/local/pgsql/share/java/postgresql.jar