7

I am running the following code in eclipse but getting a class not found exception:

         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();
        }
      }
       }

       }

and error i am getting is

    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

need help

GuruKulki
  • 25,776
  • 50
  • 140
  • 201

4 Answers4

12

As mentioned in this thread

Have you listed the org.eclipse.core.runtime as a plugin dependency in the Manfest.MF?
I think that the IStatus 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 the org.eclipse.equinox.core/runtime or similar.

Thanks for your suggestion. The problem was solved by adding org.eclipse.equinox.common and org.eclipse.core.commands to the Java Build Path property for the project - which I run as an SWT application.

As mentioned by AlBlue in the comment, the Eclipse wiki on JFace confirms:

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 the org.eclipse.osgi.
If this plug-in is absent JFace will continue to function but without the benefit of internationalization support for its images.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yeah, the documentation for JFace suggests that those need to be added. http://wiki.eclipse.org/index.php/JFace#Using_JFace_outside_the_Eclipse_platform – AlBlue Feb 22 '10 at 02:50
2

The classpath for compiling isn't necesarily the same as the runtime classpath. There is a launch config (Run->Run...) will shoe you what is there.

Note that the SWT jar is just the API classes - you'll need a per-os binary for the real runtime classes, so that might be missing. If you add the "swt" classpath container then it should do the right thing.

What's the contents of .classpath inbyout current project?

AlBlue
  • 23,254
  • 14
  • 71
  • 91
  • i have jface-3.0.1.jar and eclipse-jface-2.1.0.jar, But the first one is having ComboViewer which is needed for me, but with the first jar getting this error but with the second one it works fine. – GuruKulki Feb 21 '10 at 14:42
  • JFace needs SWT. I suspect your eclipse-jface-2.1.0.jar may have an embedded SWT in it (if that's all you have). Note that JFace 2.1 may need a lower version of SWT than JFace 3.0 does. (Plus, it's not clear where you're getting these from) Here's how to use JFace outside of an Eclipse runtime: http://wiki.eclipse.org/index.php/JFace#Using_JFace_outside_the_Eclipse_platform – AlBlue Feb 22 '10 at 02:49
0

When you run your exported product, if you see something like,

org.osgi.framework.BundleException: 
The activator org.eclipse.ui.internal.WorkbenchPlugin 
for bundle org.eclipse.ui.workbench is invalid

...

Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError

It may be fixed via:

  1. Open the product configuration editor on your product file
  2. Click the "Launching" tab
  3. clear out the "Program Arguments" and "VM Arguments" fields.
  4. Re-export the product
jcjr
  • 1,503
  • 24
  • 40
ally
  • 1
-1

Did you imported something for this?

PublishGenericArtefactDialog publishGenericArtefactDialog =            
                       new PublishGenericArtefactDialog(frame);
Pentium10
  • 204,586
  • 122
  • 423
  • 502