我在 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 theManfest.MF
?
I think that theIStatus
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 theorg.eclipse.equinox.core/runtime
or similar.感谢您的建议。通过将
org.eclipse.equinox.common
和org.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 theorg.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/