開發環境:
eclipse 3.7.1 RCP SDK
問題產生過程:
建立eclipse RCP工程,使用windowbuilder設計editor介面,將某控制項(如:label)進行資料繫結。
eclipse 後台產生代碼:
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
IObservableValue lblSysNoObserveTextObserveWidget = SWTObservables.observeText(lblSysNo);
IObservableValue sysContextSysTypesystemNameObserveValue = PojoObservables.observeValue(sysContext, "sysType.systemNo");
bindingContext.bindValue(lblSysNoObserveTextObserveWidget, sysContextSysTypesystemNameObserveValue, null, null);
return bindingContext;
}
儲存程式後運行代碼出現一下錯誤資訊。
錯誤資訊:
!SESSION 2011-11-22 22:58:20.305 -----------------------------------------------eclipse.buildId=unknownjava.version=1.6.0_22java.vendor=Sun Microsystems Inc.BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=zh_CNFramework arguments: -application teshost.applicationCommand-line arguments: -application teshost.application -data D:\work\src/../runtime-teshost.application -dev file:D:/work/src/.metadata/.plugins/org.eclipse.pde.core/teshost.application/dev.properties -os win32 -ws win32 -arch x86 -consoleLog!ENTRY org.eclipse.osgi 2 0 2011-11-22 22:58:21.360!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:!SUBENTRY 1 org.eclipse.osgi 2 0 2011-11-22 22:58:21.360!MESSAGE Bundle initial@reference:file:http://www.cnblogs.com/work/src/teshost/ was not resolved.!SUBENTRY 2 teshost 2 0 2011-11-22 22:58:21.360!MESSAGE Missing required bundle org.eclipse.core.databinding.beans_0.0.0.!ENTRY org.eclipse.osgi 2 0 2011-11-22 22:58:21.361!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:!SUBENTRY 1 org.eclipse.osgi 2 0 2011-11-22 22:58:21.362!MESSAGE Bundle teshost_1.0.0 [38] was not resolved.!SUBENTRY 2 teshost 2 0 2011-11-22 22:58:21.362!MESSAGE Missing required bundle org.eclipse.core.databinding.beans_0.0.0.!ENTRY org.eclipse.osgi 2 0 2011-11-22 22:58:21.371!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:!SUBENTRY 1 org.eclipse.osgi 2 0 2011-11-22 22:58:21.371!MESSAGE Bundle initial@reference:file:http://www.cnblogs.com/work/src/teshost/ was not resolved.!SUBENTRY 2 teshost 2 0 2011-11-22 22:58:21.372!MESSAGE Missing required bundle org.eclipse.core.databinding.beans_0.0.0.!ENTRY org.eclipse.osgi 2 0 2011-11-22 22:58:21.373!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:!SUBENTRY 1 org.eclipse.osgi 2 0 2011-11-22 22:58:21.373!MESSAGE Bundle teshost_1.0.0 [38] was not resolved.!SUBENTRY 2 teshost 2 0 2011-11-22 22:58:21.373!MESSAGE Missing required bundle org.eclipse.core.databinding.beans_0.0.0.!ENTRY org.eclipse.osgi 4 0 2011-11-22 22:58:21.374!MESSAGE Application error!STACK 1java.lang.RuntimeException: Application "teshost.application" could not be found in the registry. The applications available are: org.eclipse.equinox.app.error.at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:248)at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)at org.eclipse.equinox.launcher.Main.run(Main.java:1407)at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
An error has occurred. See the log file
錯誤原因:
產生的綁定代碼中,PojoObservables 來自於
org.eclipse.core.databinding.beans jar包。
這個jar包本在 Plug-in Dependencies中,但是項目無論如何載入不了,具體錯誤原因不明,跟進代碼調試,會報異常:
java.lang.RuntimeException: No application id has been found.
at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:242)
解決方案:
1. 找到eclipse安裝目錄下的對應jar包, 如: d:\eclipse-SDK-3.7.1-win32\eclipse\plugins\org.eclipse.core.databinding.beans_1.2.100.I20100824-0800.jar
2. 將該jar包以外部jar包形式添加到項目引用(Add Extenal JARS...)
3. 將 jar包copy到項目下的lib檔案夾下
4. 開啟項目的MANIFEST.MF檔案,轉到MANIFEST.MF Tab頁面
5. 刪除依賴項:
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime, org.eclipse.core.databinding, org.eclipse.core.databinding.beans, //刪除這一行,由於第2部的原因,項目產生代碼不會因為找到命名空間而報錯。 org.eclipse.core.databinding.observable, org.eclipse.core.databinding.property, org.eclipse.jface.databinding
6. 分別在runtime 和 build tab頁面中添加jar包的引用
7. 重新啟動執行,問題解決
PS: 該問題具體原因不明,有可能是RCP的一個bug。