Re: Plugin architectures
markspace wrote:
Certain types of existing class loaders allow you to add to its search
path. For example,
ClassLoader cl = MyClass.class.getClassLoader();
if( cl instanceof URLClassLoader ) {
((URLClassLoader)cl).addURL( urlPath );
}
would do it if your current class loader happens to be a URLClassloader.
I have no idea what the normal default type of a class loader is though.
A quick test reveals that there is some likelihood that you already have
a URLClassLoader:
<code>
public class ClassLoaderTest {
public static void main( String[] args )
{
ClassLoader cl = ClassLoaderTest.class.getClassLoader();
System.out.println( cl );
if( cl instanceof URLClassLoader ) {
System.out.println( " is a URLClassLoader" );
}
}
}
</code>
<output>
run:
sun.misc.Launcher$AppClassLoader@fabe9
is a URLClassLoader
BUILD SUCCESSFUL (total time: 1 second)
</output>
A quickie solution might be to count on having a URLClassLoader, then
just disable the plugin technology if for some reason you don't. Once
you get feedback from the field, you'll have an idea whether it would be
worth it to develop something more complex, or if the default program
behavior is good enough.
Start small, build up. Don't write code until you have to. Laziness is
a virtue. Gold-plating is an anti-pattern, and many of these
suggestions on this thread strike me as gold-plating.