如何配置 OSGi 环境以便可以从 EclipseStarter 类中使用它?
目前,我正在尝试使用 EclipseStarter 类的功能来执行一些包。 如果我直接从 Eclipse 运行我的程序,则会加载 OSGi 服务包,并且我能够安装并启动其他包。
但是,如果我将 java 程序导出到可执行 jar 文件并从命令行运行它,则环境会加载名为“System Bundle [0]”的包,而不是 OSGi 服务包。 每次尝试安装新包都会导致空指针异常。
我是否必须在框架属性中设置一些特殊配置才能使用 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)
目前我正在使用 Framework-jar-file 作为外部库我的 Eclipse 项目。 我认为当我将项目导出到可执行文件时出现问题......
BR,
Markus
Currently I'm trying to execute some bundles using the capabilities of the EclipseStarter class. If I run my program directly from Eclipse the OSGi service bundle is loaded and I'm able to install and start other bundles.
But if I export my java program to a executable jar-file and run it from the command line the environment loads a bundle called "System Bundle [0]" instead of the OSGi service bundle. Every attempt to install a new bundle causes a Nullpointer-Exception.
Do I have to set some special configuration within the Framework properties to be able to use the OSGi environment from the jar file? Currently I'm only setting the following two values:
frameworkProperties.put("osgi.clean", "true");
frameworkProperties.put("osgi.console", "true");
Update:
I think my problem might have something to do with the used java classpath. If I add the Framework-Bundle to the classpath like this
java -classpath /home/markus/org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar:test.jar
Starter.Starter
everything is working well:
osgi> ss
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.3.R34x_v20081215-1030
But if I only run the jar file I'm getting the following error log:
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)
Currently I'm using the framework-jar-file as an external library within my Eclipse project. I think that somethings goes wrong when I export my project to an executable file ...
BR,
Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还要添加以下属性
第一个属性告诉 Equinox 不要停止。 如果您不创建 Eclipse 应用程序,则这是必需的。 其他的是各种文件应该去的路径。 当您想使用控制台时,只需执行“
不需要值”即可。 如果你输入一个数字,那将是一个 telnet 端口,你可以在其中看到控制台。
现在,对于您的捆绑包,您将始终看到系统捆绑包。 那就是 OSGi 本身。 要添加其他捆绑包,您需要安装它们。 您可以通过控制台或通过配置来安装它们:
您可以使用 System Bundle 实例以编程方式安装捆绑包,您可以从 EclipseStarter 获取该实例。
如果这些不起作用,您能否上传堆栈跟踪或 osgi 日志文件(您可能会在工作目录或“osgi.configuration.area”中找到 osgi 日志文件)。 这将是一个名称纯数字的文件。
I would also add the following properties
The first one tells Equinox not to stop. This is necessary if you are not creating an Eclipse application. The other ones are paths where various files should go. When you want to use the Console, just do
No need for a value. If you put a number, that will be a telnet port where you can see the console.
Now, as for your bundles, you will ALWAYS see the System Bundle. That is OSGi itself. To add additional bundles, you need to install them. You can install them via the Console, or via config using:
You can install bundles programmatically using the System Bundle instance, which you can obtain from the EclipseStarter.
If these don't work, can you please upload a stack trace or the osgi log file (you might find the osgi log file in your working directory, or the "osgi.configuration.area"). It will be a file where the name is purely numeric.