目前我正在尝试使用 EclipseStarter 类的功能来执行一些包。如果我直接从 Eclipse 运行我的程序,则会加载 OSGi 服务包,并且我可以安装和启动其他包。
但是,如果我将我的 java 程序导出到一个可执行的 jar 文件并从命令行运行它,那么环境会加载一个名为“System Bundle [0]”的包,而不是 OSGi 服务包。每次尝试安装新包都会导致 Nullpointer-Exception。
我是否必须在框架属性中设置一些特殊配置才能使用 jar 文件中的 OSGi 环境?目前我只设置以下两个值:
frameworkProperties.put("osgi.clean", "true");
frameworkProperties.put("osgi.console", "true");
更新:
我认为我的问题可能与使用的 java 类路径有关。如果我像这样将 Framework-Bundle 添加到类路径中
java -classpath /home/markus/org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar:test.jar
Starter.Starter
一切正常:
osgi> ss
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.3.R34x_v20081215-1030
但如果我只运行 jar 文件,我会收到以下错误日志:
markus@markus-laptop:~/configuration$ cat 1244201504478.log
!SESSION 2009-06-05 13:31:44.895 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=de_DE
Command-line arguments: -clean -console
!ENTRY org.eclipse.osgi 4 0 2009-06-05 13:31:44.897
!MESSAGE An unexpected runtime error has occurred.
!STACK 0
java.lang.NullPointerException
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.readStateData(BaseStorage.java:743)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.getStateManager(BaseStorage.java:698)
at org.eclipse.osgi.baseadaptor.BaseAdaptor.getState(BaseAdaptor.java:390)
at org.eclipse.core.runtime.adaptor.EclipseStarter$1.bundleChanged(EclipseStarter.java:307)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:1234)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:141)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1518)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1469)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:281)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.launch(StartLevelManager.java:247)
at org.eclipse.osgi.framework.internal.core.SystemBundle.resume(SystemBundle.java:201)
at org.eclipse.osgi.framework.internal.core.Framework.launch(Framework.java:644)
at org.eclipse.osgi.framework.internal.core.OSGi.launch(OSGi.java:51)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:313)
at CanEmulator.OSGiFramework.run(OSGiFramework.java:119)
at java.lang.Thread.run(Thread.java:619)
!ENTRY System Bundle 4 0 2009-06-05 13:31:44.898
!MESSAGE
!STACK 0
java.lang.NullPointerException
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.readStateData(BaseStorage.java:743)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.getStateManager(BaseStorage.java:698)
at org.eclipse.osgi.baseadaptor.BaseAdaptor.getState(BaseAdaptor.java:390)
at org.eclipse.core.runtime.adaptor.EclipseStarter$1.bundleChanged(EclipseStarter.java:307)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:1234)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:141)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1518)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1469)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:281)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.launch(StartLevelManager.java:247)
at org.eclipse.osgi.framework.internal.core.SystemBundle.resume(SystemBundle.java:201)
at org.eclipse.osgi.framework.internal.core.Framework.launch(Framework.java:644)
at org.eclipse.osgi.framework.internal.core.OSGi.launch(OSGi.java:51)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:313)
at CanEmulator.OSGiFramework.run(OSGiFramework.java:119)
at java.lang.Thread.run(Thread.java:619)
目前,我在我的 Eclipse 项目中使用 framework-jar-file 作为外部库。我认为当我将项目导出到可执行文件时出现问题......
BR,
马库斯