0

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?

1 Answers1

0

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

Eranda
  • 1,439
  • 1
  • 17
  • 30
  • Any idea how I can create a jar with just some selected code (in Intellij or in command line)? – JackBlack1 May 09 '15 at 04:41
  • You need to create a multi-maven project. Where you have two project api and impl. – Eranda May 09 '15 at 14:26
  • Maven is not a mandatory option in Java, but this is not the topic ;-) In order to package properly your JARS, the point is to respect [the tutorial](http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html)... – bdulac May 15 '15 at 22:59
  • For example, the jaxb-impl.jar should contain a *META-INF/services* folder with appropriates files to specify the implemented interface(s). – bdulac May 15 '15 at 23:00
  • In your case you should have a single text file named after the interface: *META-INF/services/PluginInterface*. In the content is a single line with the full name of the implementing class... – bdulac May 15 '15 at 23:02