简体   繁体   English

osgi捆绑如何知道接口?

[英]How can a osgi bundle know about an interface?

I'm learning dealing with osgi bundles using apache felix. 我正在学习使用Apache Felix处理osgi包。 I'm using maven-bundle-plugin to generate the manifest file. 我正在使用maven-bundle-plugin生成清单文件。

I created a first bundle that contains only an interface and I export it to be used by others. 我创建了第一个仅包含接口的包,并将其导出以供其他人使用。 The second bundle contain a class that implements the interface created in the first bundle. 第二个捆绑软件包含一个类,该类实现在第一个捆绑软件中创建的接口。 I configured the second bundle to import the package exported by the first one. 我将第二个捆绑软件配置为导入第一个捆绑软件导出的软件包。

When I compile the second bundle, I get an error telling me that he can not resolve the interface. 当我编译第二个包时,出现一个错误告诉我他无法解析该接口。

I'm not sure that I understood how bundles works ... 我不确定我是否了解捆绑包的工作原理...

Thank you very much ... 非常感谢你 ...

[ Edit ] More information : I got the error when I compile using maven : [ 编辑 ]更多信息:使用maven编译时出现错误:

[INFO] Compilation failure
....../ServeurImpl.java:[17,36] error: cannot find symbol

ServeurImpl.java (line 17) : ServeurImpl.java(第17行):

public class ServeurImpl implements Serveur {

Serveur is an interface created in the first bundle. Serveur是在第一个捆绑软件中创建的接口。

Since your deploying the API in a separate bundle you would need something in the pom.xml file of the bundle implementing the API to say its available. 由于您是在单独的捆绑软件中部署API,因此在实现该API的捆绑软件的pom.xml文件中需要一些内容以使其可用。

In your pom.xml put something like this: 在您的pom.xml中输入以下内容:

    <dependency>
        <groupId>the.group</groupId>
        <artifactId>Serveur</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>bundle</type>
        <scope>provided</scope>
    </dependency>

'Provided' means the container would provide it... you said Felix. “提供”是指容器将提供它……您说Felix。

Hope that helps. 希望能有所帮助。

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

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