我正在尝试运行一个非常简单的JFace程序:

import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class HelloSWT_JFace extends ApplicationWindow{

    public HelloSWT_JFace(){
        super(null);
    }
    protected Control createContents(Composite parent){
        Text helloText = new Text(parent, SWT.CENTER);
        helloText.setText("Hello SWT and JFace");
        parent.pack();
        return parent;
    }
    public static void main(String[] args) {
        HelloSWT_JFace awin = new HelloSWT_JFace();
        awin.setBlockOnOpen(true);
        awin.open();
        Display.getCurrent().dispose();

    }

}

据我所知,所有库都已安装,并且在Eclipse中,代码没有给我任何错误。但是,当我运行时



和长错误报告:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more

有谁知道是什么原因造成的?

请注意;我查看了THIS问题并遵循了解决方案,但是安装Equinox插件无效。

最佳答案

感谢Baz提供的链接,我通过确保添加了所有必需的Jar来找到了解决方案(我错过了几个)。

必要的 jar 是:

org.eclipse.core.commands_<version info>.jar
org.eclipse.equinox.common_<version info>.jar
org.eclipse.jface_<version info>.jar
org.eclipse.osgi_<version info>.jar
org.eclipse.ui.workbench_<version info>.jar

可以在提供的Baz链接中找到更多信息: "Identify the Required External JAR Files for SWT and JFace"

09-13 05:39