I have a Java app (that should deploy as an executable JAR) that takes a JSON file as input, something like this:
"appConfig": {
"fizzClass": "com.me.myorg.FizzImpl"
// Lots of other configs
}
The config allows a user to specify what fizzClass
to use (for something, doesn't really matter what) at runtime. The thing is, I want this app to accept plugins; that is, I can (dynamically, at runtime) add JARs to the app, where perhaps other Fizz
implementations may be packaged, and then the user can specify these newly-available impls in their config files. For instance, perhaps my app only has public class FizzImpl implements Fizz
in it. Now let's say someone develops a plugin, foo-plugin.jar
that contains public class FooFizz implements Fizz
. Now, after deployed as a plugin to my app, an end user could pass the app the following config:
"appConfig": {
"fizzClass": "com.some.other.foo.FooFizz"
// Lots of other configs
}
...without getting ClassNotFoundException
s, etc. Because now FooFizz
is on the app's runtime classpath.
OSGi feels like the perfect solution for this. I'm trying to understand Apache Felix's architecture. My understanding is that I deploy my app as a JAR but include the Felix JAR as a dependency to it, which gives me access to a plugin architecture. I then have to require that plugin developers package their JARs as OSGi bundles. So first, if anything about those statements is mis-led or incorrect, please begin by correcting my understanding of how a Java JAR taps into the Felix OSGi runtime!
Assuming I'm more or less correct in my understanding, my question is: in order to develop plugins for my app, do I just follow the normal instructions for packaging bundles, or is there a special "trick" to tapping into Felix's plugin architecture?