Filip Nguyen
Filip Nguyen

Reputation: 1039

OSGi or URLClassLoader?

I have rather simple scenario:

My aplication has core jar file that contains my application's logic. This core jar should dynamically watch folder at runtime and when plugin jar is dropped there it should load it and be ready to use it. There may be many plugin jars.

What is in your experience fastest and most maintainable way to implement this? I have 2 suggestions:

1) Some OSGi container, Apache Felix File Install (to watch dir for new bundle). Whereas core jar is installed as bundle into container.

1.1 Problem is how should the core jar detect that newly installed bundle is it's plugin? Is there way to watch for every added bundle and look for some sort of settings with my unique string something like "kalazplugin"? In other words: how to distinct my plugin bundles?

2) Just watching directory for change and when jar is dropped then load it dynamically with URLClassLoader and implement it all myself. I could require some sort of configuration file for each plugin which would specify some settings for example...

Upvotes: 2

Views: 836

Answers (2)

Magne Rasmussen
Magne Rasmussen

Reputation: 303

If you go for OSGi, you could use the Extender Pattern to watch any bundles (already installed and installed later) and take any action if you determine that the bundle is one of your plugins. The pattern is easy to implement, especially on OSGi 4.2, which already contains a BundleTracker, but only marginally harder on earlier OSGi versions.

Just google 'osgi extender pattern' and you will see lots of references and implementations.

Upvotes: 2

Kane
Kane

Reputation: 8172

You could refer to the implementation of 'org.eclipse.equinox.p2.directorywatcher' that does exact thing what you want.

Upvotes: 1

Related Questions