简体   繁体   English

向服务提供者公开Java服务提供者接口

[英]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. 我正在尝试为插件/应用程序创建框架,我认为我已经决定使用Java中的服务提供商接口(SPI)来实现这一目标。 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. 所以我有一个类PluginInterface ,它将是我的SPI。 I want all plugins to implement this class (it has basic methods like doesAccept , handle , etc.). 我希望所有插件都实现此类(它具有诸如doesAccepthandle等的基本方法)。 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? 由于第3方将创建服务提供者, 因此我如何让他们在其代码中引用此Java接口(以便他们可以实现),而又没有实际提供主应用程序的源代码呢?

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. 创建两个JARs api和impl,将您的应用程序放置在impl中,然后将您需要与api的第三方开发人员共享的任何代码都放置在其中。

Example: jaxb-api.jar and jaxb-impl.jar 示例:jaxb-api.jar和jaxb-impl.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM