目前我正在尝试使用EclipseStarter类的功能执行一些bundle。如果我直接从Eclipse运行我的程序,则会加载OSGi服务包,我可以安装并启动其他包。
但是,如果我将我的java程序导出到可执行jar文件并从命令行运行它,环境会加载一个名为“System Bundle [0]”而不是OSGi服务包的包。每次安装新捆绑包的尝试都会导致Nullpointer-Exception。
我是否必须在Framework属性中设置一些特殊配置才能从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,
马库斯
我还会添加以下属性
osgi.noShutdown=true
osgi.configuration.area= (path)
osgi.baseConfiguration.area= (path)
osgi.sharedConfiguration.area= (path)
osgi.instance.area= (path)
osgi.user.area= (path)
第一个告诉Equinox不要停下来。如果您不创建Eclipse应用程序,则必须执行此操作。其他的是各种文件应该去的路径。当您想使用控制台时,就这样做
osgi.console=
不需要价值。如果您输入一个号码,那么这将是一个telnet端口,您可以在其中看到控制台。
现在,对于您的捆绑包,您将始终看到系统捆绑包。那是OSGi本身。要添加其他捆绑包,您需要安装它们。您可以通过控制台安装它们,也可以使用以下配置安装:
osgi.bundles= (comman delim list of bundle paths)
您可以使用System Bundle实例以编程方式安装bundle,您可以从EclipseStarter获取该实例。
如果这些不起作用,请上传堆栈跟踪或osgi日志文件(您可能会在工作目录中找到osgi日志文件,或者“osgi.configuration.area”)。它将是一个名称纯数字的文件。