Java plugin framework choice [closed]

Deadly 提交于 2019-11-28 02:41:49

If you are planning to have just one (or only a few) not very complex 'extension points' than perhaps a well-defined SPI and a piece of configuration might be sufficient. No need to use a plugin framework.

By piece of configuration I mean some mechanism to find your plugins. For example something like META-INF/services/ or simply listing your plugins in a configuration file.

More details (upon request):

SPI = Service Provider Interface, an "implementer-side equivalent of an API". To learn more try searching for a difference between API and SPI. However in this context it is just a fancy term for an interface to be implemented by your plugins (i.e. defines the contract for your plugins).

A nice, short article "Creating a Service Provider Interface" by Ethan Nicholas describes how to create your own SPI in similar way as it is done in several part of the Java Platform itself.

META-INF/services/ can be seen as a more generalized approach to creating SPIs. More information can be found in the respective section of the JAR File Specification.

(Disclaimer: I am the author of JSPF, so better take my comment with a grain of salt ;-)

The main reason I started with the JSPF was because I had the same problem as you have now: I was looking for a simple solution to make my thesis-project 1) extensible and 2) give it a more or less clear code structure.

The reason why I haven't decided to use an existing framework was because most of them were so heavyweight to start with, that I got lost in reading documentation and was almost forgetting my original task. So, according to your statement

We're trying to determine how to implement a simple plugin framework for a service we are implementing that allows different types of calculators to be "plugged-in".

I'd think that you could give JSPF a shot and see how far you come within one or two hours.

However, the final decision also depends a bit on what exactly you want to achieve, and the specific circumstances.

I have heard positive results from a number of individuals who have been using it to structure their projects or load plugins in their projects. On the other hand, I also know of one person in our department who discarded it again because he didn't feel it was mixing well with his programming style.

So, to answer your question briefly (and surely in a biased way), I would use

OSGi for projects and teams

  • which are large and have many people working on it
  • that justify the overhead of setting up the infrastructure
  • in need of the specific services offered

JPF for projects and teams

  • of medium size (?, honestly I am not sure about the project / team size they are targeting)
  • which are in need of more structured facilities to organize their code, like XML configurations, detailed plugin lifecycle management, extensible plugins ...

JSPF for projects and teams

  • of small size, following an agile paradigm
  • that just need something that works out of the box, without the need of configurations or setup
  • willing to sacrifice some features for simplicity

I hope you find the plugin framework most suitable for your scenario. And, no matter what you try, I would be happy to hear about your results.

If you need a really simple solution, try jin-plugin. It is a minimalistic plugin framework for Java and PHP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!