英文:
(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="[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)"
This is my 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>
答案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:<groupId>/<artifactId>/<version>
专注分享java语言的经验与见解,让所有开发者获益!
评论