(OSGi) 我如何为我的捆绑包导出一个包供导入?

huangapple 未分类评论93阅读模式
英文:

(OSGi) How do i export a package for my bundle to import?

问题

以下是翻译好的部分:

我正在从零开始编写一个用于Eclipse智能家居的OSGi捆绑包,并需要导出特定的包。
这是必需的,因为目前Karaf控制台显示了以下错误:

未解析的要求:Import-Package: com.pubnub.api

在清单文件中,我可以看到我导入了相同的包,以及其他一些包。我使用Maven导入了它,遵循官方文档此处

OSGi开发支持告诉我,我必须“导出com.pubnub.api包,以便我的捆绑包可以导入它”,但我不知道如何做到这一点。
似乎我应该“找到或创建一个导出PubNub API的捆绑包”,但这个答案让我感到困惑。

我想我需要在清单中添加一行,类似于“export-package等”,但我不知道在哪个清单中,或者这是否完全正确。我在OSGi框架中是初学者。

我尝试在类似的线程中搜索(例如此处此处),但我认为它们对我没有帮助。


这是我的清单文件,为了清晰起见:

Import-Package: org.eclipse.smarthome.core.library.types, org.eclipse.smarthome.core.thing, org.eclipse.smarthome.core.thing.binding, org.eclipse.smarthome.core.types, com.google.gson;version=" [2.8,3)", com.pubnub.api, com.pubnub.api.builder, com.pubnub.api.callbacks, com.pubnub.api.endpoints.pubsub, com.pubnub.api.models.consumer, com.pubnub.api.models.consumer.pubsub, com.pubnub.api.models.consumer.pubsub.message_actions, com.pubnub.api.models.consumer.pubsub.objects, org.slf4j;version=" [1.7,2)"

这是我的pom:

<parent>
    <groupId>org.openhab.addons.bundles</groupId>
    <artifactId>org.openhab.addons.reactor.bundles</artifactId>
    <version>2.5.3-SNAPSHOT</version>
  </parent>

  <artifactId>org.openhab.binding.safehome_se</artifactId>

  <name>openHAB Add-ons :: Bundles :: SafeHome_SE Binding</name>

  <dependencies>

    <dependency>
      <groupId>com.pubnub</groupId>
      <artifactId>pubnub-gson</artifactId>
      <version>4.31.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
英文:

I am writing from scratch an OSGi bundle for Eclipse smarthome and need to export a certain package.
This is needed because at the moment the karaf console is showing me this error:

Unresolved requirement: Import-Package: com.pubnub.api

In the manifest file i can see i import that same package, among others. I used maven to import it, following the official documentation here.

OSGi dev support is telling me I have to "export com.pubnub. API package in order for my bundle to import it", but I do not know how to do this.
It seems I should "find or make a bundle which exports the PubNub API" but this answer is confusing me.

I suppose I would need to add a line in the manifest like "export-package etc" somewhere, but I don't know in which manifest, or if this is the right way at all. I'm a beginner in the OSGi framework.

I tried searching in similar threads (like this and this) but I don't think they're helping in my case.


This is my manifest file, for clarity:

Import-Package: org.eclipse.smarthome.core.library.types, org.eclipse.smarthome.core.thing, org.eclipse.smarthome.core.thing.binding, org.eclipse.smarthome.core.types, com.google.gson;version=&quot;[2.8,3)&quot;, com.pubnub.api, com.pubnub.api.builder, com.pubnub.api.callbacks, com.pubnub.api.endpoints.pubsub, com.pubnub.api.models.consumer, com.pubnub.api.models.consumer.pubsub, com.pubnub.api.models.consumer.pubsub.message_actions, com.pubnub.api.models.consumer.pubsub.objects, org.slf4j;version=&quot;[1.7,2)&quot;

This is my pom:

&lt;parent&gt;
   &lt;groupId&gt;org.openhab.addons.bundles&lt;/groupId&gt;
   &lt;artifactId&gt;org.openhab.addons.reactor.bundles&lt;/artifactId&gt;
   &lt;version&gt;2.5.3-SNAPSHOT&lt;/version&gt;
 &lt;/parent&gt;

 &lt;artifactId&gt;org.openhab.binding.safehome_se&lt;/artifactId&gt;

 &lt;name&gt;openHAB Add-ons :: Bundles :: SafeHome_SE Binding&lt;/name&gt;

 &lt;dependencies&gt;

   &lt;dependency&gt;
     &lt;groupId&gt;com.pubnub&lt;/groupId&gt;
     &lt;artifactId&gt;pubnub-gson&lt;/artifactId&gt;
     &lt;version&gt;4.31.0&lt;/version&gt;
     &lt;scope&gt;provided&lt;/scope&gt;
   &lt;/dependency&gt;
 &lt;/dependencies&gt;

答案1

得分: 0

你需要安装一个导出该包的捆绑包。您可以使用以下命令从Karaf命令行控制台安装它:

bundle:install mvn:<groupId>/<artifactId>/<version>

英文:

You have to install a bundle that exports the package. You can install it from karaf command line console using the command

bundle:install mvn:&lt;groupId&gt;/&lt;artifactId&gt;/&lt;version&gt;

huangapple
  • 本文由 发表于 2020年4月3日 20:08:50
  • 转载请务必保留本文链接:https://java.coder-hub.com/61011614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定