2009-06-03 23 views
1

目前我正在試圖執行使用EclipseStarter類的功能,一些包。如果我直接從Eclipse運行我的程序,OSGi服務包將被加載,我可以安裝並啓動其他包。如何配置OSGi環境,以便可以從EclipseStarter類使用它?

但是,如果我在我的java程序導出到一個可執行的JAR文件和命令行運行環境加載一個名爲捆綁「系統插件[0]」,而不是OSGi服務捆綁。每次嘗試安裝新的捆綁包都會導致Nullpointer-Exception。

我必須設置框架屬性中一些特殊的配置能夠從jar文件使用OSGi環境?目前,我只設置以下兩個值:

frameworkProperties.put("osgi.clean", "true"); 
frameworkProperties.put("osgi.console", "true"); 

更新:

我想我的問題可能有些事情要與所使用的Java類路徑。如果我的框架,包到classpath中這樣

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文件,我發現了以下錯誤日誌:

[email protected]:~/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) 

目前我使用的框架-JAR文件作爲我的Eclipse項目內外部庫。我想,當我在我的項目導出到一個可執行文件出頭順心......

BR,

馬庫斯

+1

你是嵌入在應用程序的OSGi框架?或者它只是一個打算在另一個框架實例中運行的包?你使用的是哪種OSGi框架? – Cogsy 2009-06-03 08:37:31

+0

我使用的是最新的Equinox OSGi框架:org.eclipse.osgi_3.4。3.R34x_v20081215-1030.jar – Markus 2009-06-04 11:32:41

回答

3

我還要補充以下屬性

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) 

您可以安裝程序使用系統Bundle實例,您可以從EclipseStarter獲得束。

如果這些不起作用,您可以上傳一個堆棧跟蹤或osgi日誌文件(您可能會在您的工作目錄或「osgi.configuration.area」中找到osgi日誌文件)。它將是一個名稱完全是數字的文件。

相關問題