如果不创建插件,就无法在 eclipse 中使用 JFace 和 SWT
免责声明:
这是 .NET GUI 试图绕过 JAVA 内容的典型案例。
问题描述:
我正在尝试使用 JFace 和 SWT 构建一个非常简单的 GUI - 代码很简单(有很多教程),但不那么简单的是我似乎无法获得 JFace 和SWT 在插件项目之外工作。
我希望能够在我的项目中毫无麻烦地使用 JFace 和 SWT,因为我将“C:/eclipse 3.5/plugins”放入我的 CLASSPATH 中(从我的计算机 --> 属性 --> 高级 --> )环境变量)以及我可以在我的 PATH(本地用户路径和全局路径,当然)中找到的所有 swt-*.dll 作为 本文在“安装 SWT 和 JFace”框中指出。
问题是我无法从 eclipse.org 导入任何内容,除非我直接引用 buildpath 中的 jar -->图书馆 -->添加外部 jar(为了构建它,我必须添加以下 jar:org.eclipse.swt.win32.win32.x86_3.5.1.v3555a.jar、org.eclipse.jar jface_3.5.1.M20090826-0800.jar)。一旦我这样做了,它就构建得很好,但是当我将其作为“Java应用程序”运行时,我收到以下错误(我应该运行为其他东西吗?):
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
at demo.ui.test.EntryPoint.main(EntryPoint.java:18)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
我尝试调试它,基本上它被抛出一旦它尝试实例化 ApplicationWindow
类 (org.eclipse.jface.window.ApplicationWindow)。尝试重现该错误,我注释掉了所有代码,并将其替换为主代码中的以下代码,它在第一行抛出与上面相同的错误:
ApplicationWindow w = new ApplicationWindow(null); //<-- error on this line
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
问题:
问题 1:我怎样才能修复上面的错误(我想了解发生了什么)并让该死的东西运行?
问题 2:为什么这些 jar 对我的项目不可见以及如何制作它们?
由于我对 Java 和 eclipse 不熟悉,我可能错过了一些非常琐碎的事情。非常感谢任何帮助!
编辑:似乎其他人也遇到了同样的问题 --> http://www.eclipsezone.com/eclipse/forums/t60528.html - 不太清楚他们是如何解决的,感谢帮助
DISCLAIMER:
this is the classic case of .NET GUI trying to work his way around JAVA stuff.
PROBLEM DESCRIPTION:
I am trying to build a very simple GUI with JFace and SWT - the code is straightforward (there's plenty tutorials), what it's not so straightforward is that I can't seem to get JFace and SWT to work outside a plugin project.
I would expect to be able to use JFace and SWT in my project no hassle, since I put "C:/eclipse 3.5/plugins" in my CLASSPATH (from my computer --> properties --> advanced --> environment variables) and all the swt-*.dll I could find in my PATH (both local user and global PATHs, to be sure) as this article indicates in the "Installing SWT and JFace" box.
Problem is I can't import anything from eclipse.org unless I reference directly the jars from buildpath --> libraries --> add external jars (in order for it to build I have to add the following jars: org.eclipse.swt.win32.win32.x86_3.5.1.v3555a.jar, org.eclipse.jface_3.5.1.M20090826-0800.jar). Once I do that it builds fine but then when I run it as "Java Application" I get the following error (should I RUN AS something else?):
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
at demo.ui.test.EntryPoint.main(EntryPoint.java:18)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
I tried to debug this and basically it is thrown as soon as it tries to instantiate the ApplicationWindow
class (org.eclipse.jface.window.ApplicationWindow). Trying to reproduce the error, I commented out all my code and replaced it with the following in my main and it throws he same error as above on the first line:
ApplicationWindow w = new ApplicationWindow(null); //<-- error on this line
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
QUESTIONS:
Question 1: how can I fix the error above (I'd like to understand what's going on) and get the damn thing to run?
Question 2: why the jars are not visible to my project and how to make them?
I am probably missing something very trivial due to my lack of familiarity with Java and eclipse. Any help highly appreciated!
EDIT: seems like someone else had the same problem --> http://www.eclipsezone.com/eclipse/forums/t60528.html - not too clear how they solved it though, assistance appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IProgressMonitor
接口在您使用的这两个 jar 中不可用。您还需要将 org.eclipse.equinox.common 插件放在类路径中。IProgressMonitor
无需运行整个 Eclipse 环境即可使用。(这是您引用的文章中的解决方案。我最初认为 IProgressMonitor 位于 org.eclipse.core.runtime 插件中,但它已移至 org.eclipse.equinox.common,如 bug #122935)
IProgressMonitor
interface is not available in those two jars you use. You also need to put org.eclipse.equinox.common plugin on your classpath.IProgressMonitor
can be used without whole eclipse environment running.(This is solution from the article you refer to. I originally thought that IProgressMonitor is in org.eclipse.core.runtime plugin, but it has been moved to org.eclipse.equinox.common as described in bug #122935)
与上面 Peter 的观点相呼应,我总是需要添加一堆 JAR 来让事情运行(特别是对于 JFace)。通常,我需要
您可以使用 jarfinder 之类的工具来帮助发现哪些文件位于哪些 JAR 中。在 Windows 中,我似乎记得使用查找功能来查找文件系统上 eclipse 文件夹下的 zip/jar 文件中的
IProgressMonitor.class
- 因为有时实际的 JAR 可能很难跟踪向下。我通常通过查看失败原因、追踪/添加 JAR、冲洗并重复来进行工作。
做 RCP/插件似乎 Eclipse 会为你解决很多问题,做你自己的独立应用程序会带来额外的负担,但如果你坚持下去,拥有一个合适的独立的本机外观 GUI 真的很好。因此,我通常会设置普通(非插件)Eclipse 项目,它会迫使您面对这些问题(手动将 JAR 添加到类路径中)。当您想要分发项目时,它也会派上用场。
Echoing Peter's point above, I always have to add a bunch of JARs to get things running (especially for JFace). Typically, I'll need
You can use something like jarfinder to help spot what files live in what JARs. In windows I seem to remember using the find feature to look for, say,
IProgressMonitor.class
in zip/jar files under the eclipse folder on the file system - as sometimes the actual JARs can be hard to track down.I usually work by seeing what fails, tracking down / adding the JAR, rinse and repeat.
Doing RCP/plugins seems like Eclipse takes care of a lot of the issues for you, doing your own stand alone app comes with this extra baggage but its really nice to have a proper stand-alone native looking GUI if you stick with it. So I typically setup vanilla (non-plugin) eclipse projects and it forces you to confront these issues (add JARs to the classpath manually). It also comes in handy as and when you want to distribute your project.