java.lang.NoSuchMethodError: org.eclipse.swt.internal.win32.OS.GetForegroundWindow()

java.lang.NoSuchMethodError: org.eclipse.swt.internal.win32.OS.GetForegroundWindow()

目前我们正在开发 Eclipse RCP 应用程序。我正在使用

方法

OS.GetForegroundWindow()

用于获取前景 window。 当我在本地 运行 应用程序时,它工作正常。但是当我们在构建后 运行 同一个应用程序时,它会出现以下错误。(maven tycho build)

错误:

java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -clearPersistedState
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -clearPersistedState

!ENTRY org.eclipse.e4.ui.workbench.swt 4 2 2018-04-03 12:31:22.074
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.e4.ui.workbench.swt".
!STACK 0
java.lang.NoSuchMethodError: org.eclipse.swt.internal.win32.OS.GetForegroundWindow()

如果有人有解决办法请告诉我。或者如果有任何替代方法我们可以使用而不是 OS.GetForegroundWindow() .

Eclipse Bug

中找到了一些相关的参考信息

Whosebug 参考资料link:Whosebug Ref link

试试这个解决方案,让你的 shell 排在最前面,它正在 window 7

public static void forceActive(final Shell shell) {
    shell.getDisplay().asyncExec(new Runnable() {
        public void run() {
            shell.forceActive();
        }
    });
}