Java 无法启动 osgi 包,因为无法解析导入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9776885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cant start osgi bundle because import cannot be resolved
提问by reox
I have made a small API Bundle and a service bundle that should use the API.
我制作了一个小的 API 包和一个应该使用 API 的服务包。
In my maven pom.xml file, i added a dependecy for my api bundle in the correct version like this:
在我的 maven pom.xml 文件中,我在正确的版本中为我的 api 包添加了一个依赖项,如下所示:
<dependency>
<groupId>at.foobar.osgi.api</groupId>
<artifactId>foobarapi</artifactId>
<version>1.0</version>
</dependency>
i'm using the maven-bundle plugin to create the bundles, and because of that i used mvn clean install
to create by jar file.
The Manifest looks like this (the service):
我正在使用 maven-bundle 插件来创建包,因此我曾经mvn clean install
通过 jar 文件创建。清单看起来像这样(服务):
Manifest-Version: 1.0
Private-Package: at.foobar.osgi.producer
Built-By: foobar
Tool: Bnd-0.0.238
Bundle-Name: foobarproducer
Created-By: Apache Maven Bundle Plugin
Bundle-Version: 1.0
Build-Jdk: 1.6.0_26
Bnd-LastModified: 1332185439257
Bundle-ManifestVersion: 2
Bundle-Activator: at.foobar.osgi.producer.Activator
Import-Package: at.foobar.osgi.api,org.osgi.framework;version="1.4"
Bundle-SymbolicName: at.foobar.osgi.producer.foobarproducer
which seems to be OK for me. The import is in there, so everything should be fine.
这对我来说似乎没问题。导入在那里,所以一切都应该没问题。
now i started up equinox and installed the API and the producer bundle. Then i startet the API, which worked out fine. But when i want to start the Producer Service i get this error:
现在我启动了 equinox 并安装了 API 和生产者包。然后我开始使用 API,结果很好。但是当我想启动生产者服务时,我收到此错误:
org.osgi.framework.BundleException: The bundle "at.foobar.osgi.producer.foobarproducer_1.0.0 [4]" could not be resolved. Reason: Missing Constraint: Import-Package: at.foobar.osgi.api; version="0.0.0"
It seems that the framework cannot find the api, but its installed and started?
框架似乎找不到api,但它已安装并启动?
回答by Gootik
Make sure that you are exporting the API packages, so that your service bundle can bind to them.
确保您正在导出 API 包,以便您的服务包可以绑定到它们。
In your maven-bundle-plugin for the API bundle you should have something like:
在 API 包的 maven-bundle-plugin 中,您应该具有以下内容:
<configuration>
<instructions>
<Import-Package>
*
</Import-Package>
<Export-Package>
at.foobar.osgi.api.*
</Export-Package>
</instructions>
</configuration>