2

I'm creating a small hobby Java task/todo application. I want to be able to write plugins for it, which will be stored in a directory somewhere, probably in a plugins directory next to the myapplication.jar.

I have some idea on how to load these plugins, and I want to write interfaces which the plugin creator can use, like SomeActionInterface, when implemented allows the plugin to add functionality to SomeAction.

My question is, where does that SomeActionInterface go, and how would the plugin creator access said interface?

Does the interface go in the main myapplication.jar which the user should have loaded on their classpath, or does it go in a separate myapplication-plugininterfaces.jar?

Oreborous
  • 322
  • 1
  • 3
  • 14

1 Answers1

1

Normally you would expose SPI and API that the plugin authors can use to implement their code. Normally these classes are packaged as a separate JAR, this allows to have a minimal dependency to build a plugin.

There are some good examples of plugin architecture that you can explore:

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • And this API jar should also be included in the main project right? To be able to call the interfaced plugins. – Oreborous Jan 19 '19 at 10:51
  • 1
    @Oreborous If you use Maven or any other build system that allows for modules you usually end up with `api`, `application` and possibly a `common` module shared between `api`, `application`. `application` depends on `api` but not the other way. You want to make `api` a separate module and keep it small e.g. don't add 3rd party libraries there if you can avoid it. – Karol Dowbecki Jan 19 '19 at 10:54