OSGi环境搭建步骤

OSGi环境搭建步骤

  • 看一下我下的Eclipse的about, 如下图
  • run->run configuration->OSGi framework->new
  • 按照某些书籍说勾上org.eclipse.osgi这个bundle就可以,其实不然,我的这个版本是不行的。必须还选中
    1.org.eclipse.equinox.console
    2.org.apache.felix.gogo.command
    3.org.apache.felix.gogo.runtime
    4.org.apache.felix.gogo.shell

只选org.eclipse.osgi会报错如下
'!SESSION 2015-02-25 06:48:49.684 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_45
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments: -dev file:D:/Java/workspace/.metadata/.plugins/org.eclipse.pde.core/New_OSGi/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -console

!ENTRY org.eclipse.osgi 4 0 2015-02-25 06:48:50.521
!MESSAGE Could not find bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console
at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:211)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)'

然后就按提示勾上org.eclipse.equinox.console,可是又会报错:
'!SESSION 2015-02-25 06:51:08.711 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_45
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments: -dev file:D:/Java/workspace/.metadata/.plugins/org.eclipse.pde.core/New_OSGi/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -console

!ENTRY org.eclipse.equinox.console 4 0 2015-02-25 06:51:09.478
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [1]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!ENTRY org.eclipse.osgi 4 0 2015-02-25 06:51:09.481
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.console_1.0.100.v20130429-0953.jar was not resolved.

!ENTRY org.eclipse.osgi 4 0 2015-02-25 06:51:09.483
!MESSAGE Could not start bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not start bundle: org.eclipse.equinox.console
at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:217)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [1]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
... 10 more
Root exception:
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [1]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

!ENTRY org.eclipse.osgi 2 0 2015-02-25 06:51:09.517
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2015-02-25 06:51:09.517
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.console_1.0.100.v20130429-0953.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.console 2 0 2015-02-25 06:51:09.517
!MESSAGE Missing imported package org.apache.felix.service.command_0.8.0.

!ENTRY org.eclipse.osgi 2 0 2015-02-25 06:51:09.522
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2015-02-25 06:51:09.522
!MESSAGE Bundle org.eclipse.equinox.console_1.0.100.v20130429-0953 [1] was not resolved.
!SUBENTRY 2 org.eclipse.equinox.console 2 0 2015-02-25 06:51:09.522
!MESSAGE Missing imported package org.apache.felix.service.command_0.8.0.
!SUBENTRY 2 org.eclipse.equinox.console 2 0 2015-02-25 06:51:09.522
!MESSAGE Missing optionally imported package org.osgi.service.cm_0.0.0.
'

只有全部勾上了,console里才会出现
'osgi> ss
"Framework is launched."

id State Bundle
0 ACTIVE org.eclipse.osgi_3.9.1.v20140110-1610
1 ACTIVE org.eclipse.equinox.console_1.0.100.v20130429-0953
2 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036
3 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605
4 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215
osgi> '
这就说明环境好了,接下来可以写个HelloWorld了。

  1. [OSGi联盟组织官网](http://www.osgi.org/Main/HomePage)
posted @ 2015-02-25 17:36  nateliu  阅读(572)  评论(0)    收藏  举报