Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting class not found Exception when running in eclipse

Tags:

java

eclipse

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

like image 749
GuruKulki Avatar asked Feb 21 '10 14:02

GuruKulki


2 Answers

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.

like image 125
VonC Avatar answered Oct 29 '22 13:10

VonC


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?

like image 40
AlBlue Avatar answered Oct 29 '22 15:10

AlBlue