2013-05-10 65 views
1

我想運行一個非常簡單的JFace程序:無法編譯簡單的JFACE程序; java.lang.NoClassDefFoundError

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插件不起作用。

+1

你加'org.eclipse.core.runtime <版本> .jar'到你的項目? – Baz 2013-05-15 17:42:17

+2

[This](http://wiki.eclipse.org/JFace#Identify_the_Required_External_JAR_Files_for_SWT_and_JFace)也可能有幫助。 – Baz 2013-05-15 18:12:26

+0

@Baz是的,我做過 – CodyBugstein 2013-05-17 15:04:11

回答

1

感謝Baz提供的鏈接,我找到了解決方案,確保所有必需的罐子都添加了(我錯過了一對)。

必要的罐子:

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 

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

+0

這不正是*我發佈的鏈接中的罐子清單嗎? – Baz 2013-05-17 15:44:07

+0

是的,它是完全的,這就是爲什麼我確切地指定誰提供它。那是你的失望嗎? – CodyBugstein 2013-05-17 15:48:08

+0

難道你不認爲我應該提供這個答案,因爲我發佈了鏈接? – Baz 2013-05-17 15:48:41