0

我尝试在 Mac (OS 10.8.4) 上使用 Eclipse Kepler 开始开发包。我创建了一个最小的“Hello World”包并创建了一个相应的 OSGI-Framework 启动配置。启动启动配置时,我总是遇到以下异常:

osgi> !SESSION 2013-09-08 23:03:50.713 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_51
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=de_DE
Command-line arguments:  -dev file:/Users/stephan/Documents/workspace/.metadata/.plugins/org.eclipse.pde.core/New_configuration (1)/dev.properties -os macosx -ws cocoa -arch x86_64 -consoleLog -console

!ENTRY org.eclipse.core.net 1 0 2013-09-08 23:03:53.012
!MESSAGE System property http.nonProxyHosts has been set to local|*.local|169.254/16|*.169.254/16 by an external source. This value will be overwritten using the values from the preferences
***WARNING: Display must be created on main thread due to Cocoa restrictions.

!ENTRY org.eclipse.equinox.preferences 4 2 2013-09-08 23:03:53.293
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.equinox.preferences".
!STACK 0
java.lang.ExceptionInInitializerError
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setDefault(DebugUIPreferenceInitializer.java:186)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setThemeBasedPreferences(DebugUIPreferenceInitializer.java:204)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.initializeDefaultPreferences(DebugUIPreferenceInitializer.java:79)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:300)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.runInitializer(PreferenceServiceRegistryHelper.java:303)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.applyRuntimeDefaults(PreferenceServiceRegistryHelper.java:131)
    at org.eclipse.core.internal.preferences.PreferencesService.applyRuntimeDefaults(PreferencesService.java:368)
    at org.eclipse.core.internal.preferences.DefaultPreferences.applyRuntimeDefaults(DefaultPreferences.java:221)
    at org.eclipse.core.internal.preferences.DefaultPreferences.load(DefaultPreferences.java:274)
    at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:409)
    at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:670)
    at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:812)
    at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:38)
    at org.eclipse.core.runtime.preferences.DefaultScope.getNode(DefaultScope.java:76)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getDefaultPreferences(ScopedPreferenceStore.java:250)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getPreferenceNodes(ScopedPreferenceStore.java:285)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.internalGet(ScopedPreferenceStore.java:475)
    at org.eclipse.ui.preferences.ScopedPreferenceStore.getString(ScopedPreferenceStore.java:535)
    at org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager.initPerspectives(PerspectiveManager.java:996)
    at org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager.startup(PerspectiveManager.java:269)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.start(DebugUIPlugin.java:542)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
    at org.eclipse.swt.SWT.error(SWT.java:4397)
    at org.eclipse.swt.SWT.error(SWT.java:4312)
    at org.eclipse.swt.SWT.error(SWT.java:4283)
    at org.eclipse.swt.widgets.Display.error(Display.java:1076)
    at org.eclipse.swt.widgets.Display.createDisplay(Display.java:833)
    at org.eclipse.swt.widgets.Display.create(Display.java:816)
    at org.eclipse.swt.graphics.Device.<init>(Device.java:130)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:707)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:698)
    at org.eclipse.swt.widgets.Display.getDefault(Display.java:1396)
    at org.eclipse.jface.preference.PreferenceConverter.<clinit>(PreferenceConverter.java:81)
    ... 37 more

我使用 Apple JDK 1.6.0_51 和 Oracle JDK 1.7.0_25 进行了尝试。我也试过 -XstartOnFirstThread开关。我总是得到同样的错误。

捆绑包如下所示:

package testbundle;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

/*
 * (non-Javadoc)
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
public void start(BundleContext context) throws Exception {
    System.out.println("Hello World!!");
}

/*
 * (non-Javadoc)
 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
 */
public void stop(BundleContext context) throws Exception {
    System.out.println("Goodbye World!!");
}

}

也许有人可以给我一个提示。

谢谢斯蒂芬

4

1 回答 1

1

我认为 Eclipse 包必须以 START_ACTIVATION_POLICY 标志启动,因为它们在其激活器中包含 SWT 代码,因此假设(错误地!)它们位于主线程上。

如果你有 Eclipse/SWT 包,基本上你不应该使用 PDE 的“OSGi 框架”启动器。您应该使用“Eclipse Application”启动器,就像您正在开发 RCP 应用程序一样。

于 2013-09-09T16:42:59.180 回答