Search code examples
javaservice-provider

Expose a Java Service Provider Interface to Service Providers


I'm trying to create a framework for plugin/apps, and I think I've settled on using a Service Provider Interface (SPI) in Java to achieve that. The ultimate vision is that people can download plugins (like an app store) and then just drop the jars into a folder, and they'll work with the existing program.

So I have a class PluginInterface that will be my SPI. I want all plugins to implement this class (it has basic methods like doesAccept, handle, etc.). Since 3rd parties will be creating the Service Providers, how can I let them reference this Java interface in their code (so they can implement it), without actually giving them the source code of the main application?


Solution

  • Create two JARs api and impl where you put your application in the impl and put whatever the code you need to share with third party developer in api.

    Example: jaxb-api.jar and jaxb-impl.jar