java - 在eclipse中运行时找不到类异常

标签 java eclipse

我在 eclipse 中运行下面的代码,但得到了一个找不到类的异常:

         import org.eclipse.jface.window.Window;
         import org.eclipse.swt.SWT;
         import org.eclipse.swt.widgets.Display;
         import org.eclipse.swt.widgets.Shell;



        public class DialogClass {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.println("TEst");
    Shell frame = new Shell(SWT.SHELL_TRIM);

    PublishGenericArtefactDialog publishGenericArtefactDialog =            
                       new PublishGenericArtefactDialog(frame);

    publishGenericArtefactDialog.setTitle("Test");

    if (publishGenericArtefactDialog.open() == Window.CANCEL){
        try {
            throw new Exception("Cancelled");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      }
       }

       }

我得到的错误是

    TEst
    Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IStatus
at DialogClass.main(DialogClass.java:19)
     Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IStatus
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more

需要帮助

最佳答案

this thread 中所述

Have you listed the org.eclipse.core.runtime as a plugin dependency in the Manfest.MF?
I think that the IStatus is actually in an Equinox package, but the runtime includes the equinox plugin at runtime.
If you're just running it as a Java application (e.g. by sticking Jars on the classpath) then you'll probably need the org.eclipse.equinox.core/runtime or similar.

感谢您的建议。通过将 org.eclipse.equinox.commonorg.eclipse.core.commands 添加到项目 - 我将其作为 SWT 应用程序运行。

AlBlue 所述在评论中,Eclipse wiki on JFace确认:

JFace can be used in standalone SWT+JFace apps, without requiring the Eclipse Runtime or other parts of the Eclipse Platform.
This was made easier to do in 3.2 (2006), with the only prerequisites for JFace being reduced to:

  • SWT,
  • the new org.eclipse.equinox.common plug-in,
  • and org.eclipse.core.commands plug-in.

For more details, see Bug 49497.

In 3.3 an optional dependency on the org.osgi.framework package was added which is defined in the org.eclipse.osgi.
If this plug-in is absent JFace will continue to function but without the benefit of internationalization support for its images.

关于java - 在eclipse中运行时找不到类异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2306133/

相关文章:

java - Eclipse插件: Link MulitPageEditorPart with Navigator

java - 使用 Pico 编译器 - Ipad 运行时,在 Java 中使用 switch() 和 Scanner 会出现错误

java - 即使框架已 setVisible(false) 也无法 SetUndecorated

java - 如何获取使用 Intent.ACTION_OPEN_DOCUMENT 选择的文件的文件扩展名?

java - JAVA 不能抛出 AuthenticationException 类型的异常

java - Android:计算并输出到textview

eclipse - 在 Eclipse 中切换测试和类的键盘快捷键?

java - Git 管理环境特定配置

java - 在 Tsurgeon 中将节点插入树时如何命名节点

Eclipse - Tomcat VM 参数没有改变