Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

I'm trying to do an initial setup with Hibernate in Eclipse, while deploying with Tomcat.

I encountered the following problem:

java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    db.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
    db.HibernateUtil.<clinit>(HibernateUtil.java:8)

I've goggled my problem online and I understand that it has something to to with the project class path.

I've added a user library to my project containing all the jars under the "required" directory in the hibernate download, but that doesn't seem to work.

Please find a screen shot of my project here:

like image 961
Blue Avatar asked Mar 24 '12 11:03

Blue


4 Answers

This error can happen when your jar files has not been exported with your web archive. You can do what @Chris White has said or you can follow below steps if you are using Eclipse.

Right click the project -> Build Path -> Configure Build Path

In the list at left side click on Deployment Assembly. Click "Add" button. Select "Java Build Path Entries" and click next. Now select your hibernate jar files or library. Click finish. Then click Ok.
Restart the server if necessary.

like image 133
prageeth Avatar answered Oct 25 '22 05:10

prageeth


You're getting the error because the hibernate libraries are not available to Tomcat. In your picture, below the hibernate library set there is an empty set called 'Web App Libraries' - this is the set your hibernate libraries need to be in.

Right click your project -> Build Path -> Configure Build Path, and remove the hibernate set from the build path. Now import the jars into the WEB-INF/lib folder. Refresh your project and now you should see them listed in the 'Web App Libraries' set (i appreciate this is somewhat annoying that you have to import them into your code base - someone else might know a better way to do this that doesn't involve copying the jars in)

like image 44
Chris White Avatar answered Oct 25 '22 05:10

Chris White


Simpler way than Chris White's way.

You're getting the error because the hibernate libraries are not available to Tomcat. Right click your project -> Build Path -> Configure Build Path, and remove the hibernate set from the build path.

Do the same stuff, but instead of importing the jars everytime for a new project, **copy the required hibernate jars in lib folder of Apache Tomcat **(or whatever the server u are using).

like image 3
Krishna Choudhary Avatar answered Oct 25 '22 03:10

Krishna Choudhary


You don't have the hibernate jar present in your library folder Visit the below link for the possible solution, http://www.smashplus.info/2012/11/javalangnoclassdeffounderror.html

like image 2
Shams Avatar answered Oct 25 '22 05:10

Shams