Search code examples
javajakarta-eeosgiclassloader

Adding jars to java application using Interface name


I am developing a media application where the user should be able to dynamically load tools from a central database at runtime. These will mostly need to be signal processing modules for manipulating audio and video. I have been reading about implementing a custom class loader, but it seems that one must know the names of the classes in order to use the classLoader. This doesn't seem right to me. I want to be able to build these modules after the application has been deployed (and possibly open up a public api for their creation).

I was thinking of requiring the modules to extend an abstract class that implements an interface:

public abstract class AbstractModule implements myInterface{
    //....
}

I still don't have any way of knowing what the authors of these Modules will name the subclass...

I have read a bit about osgi bundles, and that seems promising... However I obviously dont want to redesign my entire architecture... is it possible to have this part of my application use Osgi bundles? My feeling is no, since it seems that Osgi bundles require their own container to run in.

Anyway, what is the best, least hacky, and most stable way to let my applcation load modules dynamically. The modules need some sort of standardization (like extending an abstract class).

Thanks


Solution

  • This is such a beautiful use case for OSGI. So I guess the question is - is this a desktop application or server based? Note that it IS possible to use OSGI on the Desktop, but your container choices will be different if you go this route.


    EDIT

    For Desktop applications you would best be served by using Felix or Eclipse Equinox. Both can be embedded very nicely into standalone, rich clients. For server applications I cannot recommend JBoss 7 highly enough. You get a fast Java EE 6 server with first class support for OSGI modules. I'm still unsure on the exact setup of your architecture, you mention both a (rich sounding) client and a Java EE server. Could you elaborate some more?