Can't use JFace and SWT in eclipse without creating plugin

JohnIdol picture JohnIdol · Dec 23, 2009 · Viewed 7.1k times · Source

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

Answer

Peter Štibran&#253; picture Peter Štibraný · Dec 23, 2009

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)