Eclipse can not find the main class


I'm using Eclipse 3.7.2 on Ubuntu 12.04 with OpenJDk 7 installed

java -version gives

java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu3)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

And whenever I try to run a project, I'm getting the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: test/Example
Caused by: java.lang.ClassNotFoundException: test.Example
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
Could not find the main class: test.Example. Program will exit.

This happens for all the projects, which I have compiled successfully on my Windows system. And, when using the javac and java directly from the terminal, it works. Is there an easy solution? Is this because of OpenJDK?

The class code is :

package test;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Example extends JFrame {

    private static final long serialVersionUID = 1L;

    public Example() {
       setTitle("Simple example");
       setSize(300, 200);

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Example ex = new Example();

UPDATE: My source is in a folder called swingtest. While debugging, I found that Eclipse is using the classpath of the source as swingtest/swingtest/src/test/ rather than swingtest/src/test/ . Can this be corrected?

This error can occur because of below reason

  1. Might be missing a dependency/Required jar. To find if the jar is missing click on project->Java Build Path->source at the top you can see a error message xyz.jar is missing. So add that particular jar by clicking add external jars option

  2. May be java classpath is not set. So configure the JDK classpath both in eclipse and also environmental setup

  3. Try to clean the project and see if its rectified