Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Class Def Found Error Java

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
java.lang.NoClassDefFoundError: FirstExample
Exception in thread "main"

I am running the following Hibernate code from Eclipse and getting the error. Does anyone know what could be the problem.

All other java code works on the Eclipse IDE except this one. So I guess the classpath should have been set properly.

Code:
package roseindia.tutorial.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
 * @author Deepak Kumar
 *
 * [URL unfurl="true"]http://www.roseindia.net[/URL]
 * Hibernate example to inset data into Deals table
 */
public class FirstExample {
    public static void main(String[] args) {
        Session session = null;

        try{
            // This step will read hibernate.cfg.xml and prepare hibernate for use
            SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
             session =sessionFactory.openSession();
                //Create new instance of Contact and set values in it by reading them from form object
                 System.out.println("Inserting Record");
                Deals deal = new Deals();
                deal.setId(6);
                deal.setResultID(9999);
                deal.setDeal("This is a latest test deal");
                session.save(deal);
                System.out.println("Done");
        }catch(Exception e){
            System.out.println(e.getMessage());
        }finally{
            // Actual contact insertion will happen at this step
            session.flush();
            session.close();

        }        

    
    }
}
 
Deal Code

Code:
package roseindia.tutorial.hibernate;

/**
 * @author Deepak Kumar
 *
 * [URL unfurl="true"]http://www.roseindia.net[/URL]
 * Java Class to map to the datbase Contact Table
 */
public class Deals {
	private int ResultID;
	private String Deal;
	private long id;

	/**
	 * @return Email
	 */
	public String getResultID() {
		return ResultID;
	}

	/**
	 * @return First Name
	 */
	public String getDeal() {
		return Deal;
	}

	/**
	 * @param string Sets the Email
	 */
	public void setResultID(int string) {
		ResultID = string;
	}

	/**
	 * @param string Sets the First Name
	 */
	public void setDeal(String string) {
		Deal = string;
	}

	/**
	 * @return ID Returns ID
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param l Sets the ID
	 */
	public void setId(long l) {
		id = l;
	}

}
 
Are you specifying the full package path to the class when you run it?
That is :-
Code:
roseindia.tutorial.hibernate.FirstExample

... and are you SURE the class is on the classpath? You need to add the root directory (the one containing your 'roseindia' directory) to the classpath.

Tim
 
The most probable cause for this is a missing jar file in the classpath, but also that a class or product has been compiled with a different jar version.

Cheers,
Dian
 
I am using the Eclipse IDE. Is there a way that I can add the Classpath on the Eclipse IDE to test it.

I have created a Workspace called Hibernateexample and in the src folder of the project I have added the FirstExample and Deals java file in the src folder. Also I have created a folder called roseindia and Folder Hibernate and Folder tutorial.

I have downloaded the Hibernate project into C:\apps\Hibernate and added this folder to the classpath.

Or is it possible to just test from the command prompt? How do I do that if I try..

Cheers
Arun

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top