简体   繁体   English

如何配置OSGi环境,以便可以从EclipseStarter类使用它?

[英]How do I configure an OSGi environment so that it is possible to use it from the EclipseStarter class?

Currently I'm trying to execute some bundles using the capabilities of the EclipseStarter class. 目前,我正在尝试使用EclipseStarter类的功能来执行一些捆绑软件。 If I run my program directly from Eclipse the OSGi service bundle is loaded and I'm able to install and start other bundles. 如果我直接从Eclipse运行我的程序,则OSGi服务捆绑软件已加载,并且我能够安装和启动其他捆绑软件。

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. 但是,如果我将Java程序导出到可执行的jar文件并从命令行运行,则环境会加载一个名为“系统包[0]”的包,而不是OSGi服务包。 Every attempt to install a new bundle causes a Nullpointer-Exception. 每次尝试安装新的捆绑软件都会导致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? 我是否必须在Framework属性中设置一些特殊配置才能使用jar文件中的OSGi环境? 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. 我认为我的问题可能与使用的Java类路径有关。 If I add the Framework-Bundle to the classpath like this 如果我像这样将Framework-Bundle添加到类路径

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: 但是,如果我只运行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)

Currently I'm using the framework-jar-file as an external library within my Eclipse project. 目前,我正在使用framework-jar-file作为Eclipse项目中的外部库。 I think that somethings goes wrong when I export my project to an executable file ... 我认为将项目导出到可执行文件时出了点问题...

BR, BR,

Markus 马库斯

I would also add the following properties 我还将添加以下属性

osgi.noShutdown=true

osgi.configuration.area= (path)
osgi.baseConfiguration.area= (path)
osgi.sharedConfiguration.area= (path)
osgi.instance.area= (path)
osgi.user.area= (path)

The first one tells Equinox not to stop. 第一个告诉Equinox不要停止。 This is necessary if you are not creating an Eclipse application. 如果不创建Eclipse应用程序,则这是必需的。 The other ones are paths where various files should go. 其他的是各种文件应存放的路径。 When you want to use the Console, just do 当您要使用控制台时,只需执行

osgi.console=

No need for a value. 不需要值。 If you put a number, that will be a telnet port where you can see the console. 如果输入数字,那将是一个telnet端口,您可以在其中查看控制台。

Now, as for your bundles, you will ALWAYS see the System Bundle. 现在,对于您的捆绑包,您将始终看到系统捆绑包。 That is OSGi itself. 那就是OSGi本身。 To add additional bundles, you need to install them. 要添加其他捆绑包,您需要安装它们。 You can install them via the Console, or via config using: 您可以通过控制台或通过使用以下命令的配置来安装它们:

osgi.bundles= (comman delim list of bundle paths)

You can install bundles programmatically using the System Bundle instance, which you can obtain from the EclipseStarter. 您可以使用系统捆绑包实例以编程方式安装捆绑包,该实例可以从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"). 如果这些方法不起作用,能否请您上载堆栈跟踪或osgi日志文件(您可能会在工作目录或“ osgi.configuration.area”中找到osgi日志文件)。 It will be a file where the name is purely numeric. 这将是一个名称纯数字的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置RMI环境,以便能够在“真实”网络中使用它? - How do I have to configure a RMI environment so that I'm able to use it in a “real” network? 如何在可停靠点中使用 osgi 服务? - How do I use an osgi service in a dockable? 如何从OSGi运行时环境中按类名字符串加载类? - How to load a class by classname string from OSGi runtime environment? 我如何从主类调用textArea以便我可以在另一个类中使用它? - How do iI call textArea from main class so that I can use it in another class? 是否可以使用 react native 和 springboot,如果可以,我该如何配置数据库连接 - Is it possible to use react native and springboot,if so how can i configure a database connection 如何在OSGI中使用带有嵌入式.so文件的jar - How to use jar with embedded .so file in OSGI 如何同时设置OSGi和非OSGi WAR以使用外部属性文件 - How do I set up both OSGi and non-OSGi WARs to use an external properties file 如何在OSGi包中使用Spring bean? - How do I use a Spring bean inside an OSGi bundle? 如何从系统环境中定义的外部属性文件配置 Spring Boot 数据源? - How do I configure a Spring Boot datasource from an external properties file defined in the system environment? 使用另一个OSGi捆绑包中的类 - Use class from another OSGi bundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM