Eclipse无法在JFace中找到主类?

时间:2011-12-03 18:35:36

标签: java eclipse jface

我正在通过曼宁出版社的一本书SWT / JFace IN ACTION工作。

当我添加JFace时,Eclipse由于某种原因无法找到主类,尽管它显然存在。

这是代码

package com.swtjface.ChTwo;

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

public class HelloSWT_JFace extends ApplicationWindow{

/**
 * @param args
 */
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) {
    // TODO Auto-generated method stub
    HelloSWT_JFace awin = new HelloSWT_JFace();
    awin.setBlockOnOpen(true);
    awin.open();
    Display.getCurrent().dispose();
}

 }

我从Eclipse获得的拒绝消息是......

Could not find the main class: com.swtjface.ChTwo.HelloSWT_JFace.
Program will exit.

以下是例外......

java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
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)
Exception in thread "main"

2 个答案:

答案 0 :(得分:1)

你需要至少2个罐才能使用JFace:

  • org.eclipse.equinox.common
  • org.eclipse.core.commands

有关详细信息,请参阅Using JFace outside the Eclipse platform

答案 1 :(得分:0)

你需要为“org.eclipse.core.runtime.IProgressMonitor class”添加jar文件

检查this link