Java插件框架选择 [英] Java plugin framework choice
问题描述
我们正在尝试确定如何为我们正在实施的服务实现一个简单的插件框架,允许不同类型的计算器插入。
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".
阅读有关Java插件框架的帖子的数量后,似乎最常见的选项是:
After reading a number of posts about Java plugin frameworks, it seems like the most common options are:
- OSGI
- 滚动你自己的插件框架
- Java插件框架(JPF)
- Java简单的插件框架(JSPF)
- OSGI
- "Rolling your own" plugin framework
- The Java Plugin Framework (JPF)
- The Java Simple Plugin Framework (JSPF)
OSGI似乎超出了我们的需要。
OSGI seems to be more than we need.
滚动你自己是好的,但重用一个公共库会很好。
"Rolling your own" is ok but it would be nice to reuse a common library.
所以我们归结为JPF和JSPF。 JPF似乎不再处于活跃开发状态。
So we're down to the JPF and JSPF. JPF doesn't seem to be in active development anymore.
JSPF似乎非常简单,而且我们真的需要它们。但是我没有听到太多关于它的消息。我只看过一个发布关于它的StackOverflow。有没有其他人有JSPF的经验?或者对此设计选择的任何其他评论?
JSPF seems very simple and really all we need. However I haven't heard much about it. I've only seen one post on StackOverflow about it. Does anyone else have any experience with JSPF? Or any other comments on this design choice?
更新:对此不一定是正确答案..但是我们'重新考虑Pavol的想法,因为我们只需要一个非常简单的解决方案。感谢EoH的好导游。
Update: There isn't necessarily a correct answer to this.. however we're going to go with Pavol's idea as we need just a really, really simple solution. Thanks EoH for the nice guide.
推荐答案
如果你打算只有一个(或者只有几个)不是很复杂的话扩展点'可能是一个明确定义的SPI和一个配置可能就足够了。不需要使用插件框架。
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.
通过一段配置我的意思是找到你的插件的一些机制。例如 META-INF / services /
或简单地将您的插件列在配置文件中。
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.
更多细节(根据要求):
SPI = 服务提供者接口,API的实现者端等价物。要了解更多信息,请尝试搜索API和SPI之间的差异。然而,在这种情况下,它只是一个由你的插件实现的接口的一个奇特的术语(即定义你的插件的合同)。
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).
一篇不错的短篇文章 Ethan Nicholas的创建服务提供商界面描述了如何以类似于在Java平台本身的几个部分中完成的方式创建自己的SPI。
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 /
可被视为创建SPI的更通用方法。更多信息可以在 JAR文件规范。
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.
这篇关于Java插件框架选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!