java - 无法编译简单的JFACE程序; java.lang.NoClassDefFoundError

标签 java compiler-errors swt classpath jface

我正在尝试运行一个非常简单的 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 中的代码没有给我任何错误。尽管如此,当我运行时我得到了

JVM Error

和长错误报告:

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 提供的链接,我通过确保添加了所有必要的 Jars 找到了解决方案(我缺少了几个)。

必要的 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"

关于java - 无法编译简单的JFACE程序; java.lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16490431/

相关文章:

php - undefined variable 和mysqli错误

java - SWT 布局中的复合排序

java - 如何正确使用 CheckboxTreeViewer?

java - 通过线程停止无限循环函数

java - 如何将 TextView 的值放入 if 语句中

java - "is not abstract and does not override abstract method"错误

c++ - C++ 17静态模板惰性评估

swt - FormLayout、FormData 和控件

Java 类无法在具有 Maven 依赖项的 Netbeans 之外编译工作

java - java中二叉搜索树的层序遍历