【发布时间】:2018-11-11 16:58:28
【问题描述】:
我是 OSGI 新手,目前遇到以下问题:
我正在尝试编写一个带有托管服务的 OSGI 模块,它应该根据配置返回不同语言的 hello world 字符串。我已经下载了 Equinox 并将其添加到我的 Eclipse IDE 中的 Preferences/Plug-in Development/Target platform/Content 下。然后当我尝试在 MANIFEST.ML 中导入我需要的包时
Import-Package: org.osgi.framework;version="1.3.0", org.eclipse.equinox.cm, org.eclipse.osgi.services
Eclipse 警告我没有可用的包导出这些包(我已在 Preferences/Plug-in Development/Target platform/ 下勾选它们),即使 Eclipse 然后识别类如 ManagedService。 当我尝试运行该项目时,我得到以下输出:
WARNING: Using incubator modules: jdk.incubator.httpclient
Hello World
!SESSION 2018-11-11 17:34:31.981 -----------------------------------------------
eclipse.buildId=unknown
java.version=9.0.4
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=de_AT
Command-line arguments: -dev file:C:/Users/SpaceLama/eclipse-workspace/.metadata/.plugins/org.eclipse.pde.core/New_configuration/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -console
!ENTRY HelloWorld 4 0 2018-11-11 17:34:32.505
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Could not resolve module: HelloWorld [33]
Unresolved requirement: Import-Package: translator
-> Export-Package: translator; bundle-symbolic-name="Translator"; bundle-version="1.0.0.qualifier"; version="0.0.0"
Translator [69]
Unresolved requirement: Import-Package: org.eclipse.equinox.cm
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1685)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1665)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1627)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1558)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:233)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:343)
!ENTRY org.eclipse.osgi.services 4 0 2018-11-11 17:34:32.552
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Could not resolve module: org.eclipse.osgi.services [61]
Unresolved requirement: Import-Package: javax.servlet; resolution:="optional"
Unresolved requirement: Import-Package: javax.servlet.http; resolution:="optional"
Unresolved requirement: Import-Package: org.osgi.util.function; version="[1.0.0,2.0.0)"
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1685)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1665)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1627)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1558)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:233)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:343)
!ENTRY Translator 4 0 2018-11-11 17:34:32.552
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Could not resolve module: Translator [69]
Unresolved requirement: Import-Package: org.eclipse.equinox.cm
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1685)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1665)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1627)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1558)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:233)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:343)
!ENTRY org.eclipse.osgi 4 0 2018-11-11 17:34:32.552
!MESSAGE Bundle initial@reference:file:../../eclipse-workspace/HelloWorld/ was not resolved.
!ENTRY org.eclipse.osgi 4 0 2018-11-11 17:34:32.552
!MESSAGE Bundle initial@reference:file:../../eclipse-workspace/Translator/ was not resolved.
!ENTRY org.eclipse.osgi 4 0 2018-11-11 17:34:32.552
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.osgi.services_3.7.100.v20180827-1536.jar was not resolved.
【问题讨论】: