How a java application should discover extensions in runtime?
<p>I want to look for extension jars in a predefined directory and examine their manifest. Those which match should be loaded, those which do not - should be unloaded.</p>

<p>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:</p>

<pre><code>java -jar myapp.jar --pluginDir=c:/a/b/c --exts="classA;classB;classC"
</code></pre>

<p>Then myapp would iterate over all the files inside the <code>pluginDir</code> and try to load each of <code>classA</code>, <code>classB</code> or <code>classC</code>. Once a <code>classX</code> 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.</p>

<p>A slightly more javaish approach seems to be writing something in the manifest of extension jars and check the manifest of each found jar. </p>

<p>Can anyone show a working code snippet of this approach or of anything better, if there is?</p>

<p><strong>EDIT</strong></p>

<p>A quote from the postgre JDBC driver README file (see <a href="http://stackoverflow.com/a/12480373/80002">http://stackoverflow.com/a/12480373/80002</a>):</p>

<pre><code>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 
</code></pre>
