sweety
sweety

Reputation: 231

NoClassDefFoundError

I am working with the hibernate and at the time of using hibernate Connection i am getting Error as below

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.Configuration
at com.ensarm.niidle.server.SchemaManager.getDatabaseSession(SchemaManager.java:60)
at com.ensarm.niidle.server.helper.UserServiceHelper.createNiidleUser(UserServiceHelper.java:27)
at com.ensarm.niidle.server.UserSignUpServlet.doPost(UserSignUpServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

Please help me in solving it i have added all the required hibernate jar files with the lib folder of my Web App.

now what should i do?

Upvotes: 1

Views: 11543

Answers (4)

AdrianRM
AdrianRM

Reputation: 2771

I was just having a very similar exception message using Hibernate 3.5.4 ('java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.AnnotationConfiguration') and it was related to logging, as Luke Woodward pointed out. So I would guess that you are missing a slf4j implementation with its corresponding dependencies.

The link that luis.espinal provided ( http://forum.springsource.org/showpost.php?s=f3b5de4e9df29e65d4c9acaafc1676c8&p=219678&postcount=10 ) points to possible JARs that you could be missing. Among them is slf4j-log4j12-1.5.0.jar .

On top of this, the pom.xml in the 'First Hibernate Application' tutorial in the online hibernate documentation contains an explicit reference to a slf4j implementation:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/tutorial.html#tutorial-firstapp-setup

I was using the Ant Maven Tasks and my problem was solved adding the dependency to slf4j-log4j12.

Upvotes: 0

Luke Woodward
Luke Woodward

Reputation: 64959

I suspect you're missing a log4j jar or a commons-logging.jar.

The message Could not initialize class org.hibernate.cfg.Configuration means that the JVM has already tried and failed to initialize the class org.hibernate.cfg.Configuration. The source code of the class contains the following line:

private static Log log = LogFactory.getLog( Configuration.class );

Since this field is marked static, the field's value is set when the class has initialized. This field is the only static member of this class, and so if the JVM has failed to initialize this class, there must have been a problem with this field.

Upvotes: 6

luis.espinal
luis.espinal

Reputation: 10529

What arjan said. The error you are having doesn't say that it cannot find cfg.Configuration. It simply says that somewhere in the initialization of cfg.Configuration, a class definition was not found. Were there other exceptions in your log?

This smells to me classes cfg.Configuration depends on are missing from your app's WEB-INF/lib directory.

Take a look at this thread in the Spring Forums, they seem to talk about the problem you are having:

http://forum.springsource.org/showthread.php?t=65296

In particular see this post made by one of the senior members where he mentions four additional jars that were missing (mind you, this was in 2008, and I have no clue what hibernate and spring versions you are using):

http://forum.springsource.org/showpost.php?s=f3b5de4e9df29e65d4c9acaafc1676c8&p=219678&postcount=10

Hope it helps.

Upvotes: 2

Arjan Tijms
Arjan Tijms

Reputation: 38163

java.lang.NoClassDefFoundError is a tricky exception. It doesn't necessarily mean the class is not there. Instead, it's thrown to indicate there has been some problem when first initializing the class.

This is particularly troublesome when the very first access to this class runs into this problem (and the root problem is reported here), but subsequent accesses to the class only spit out the dreaded java.lang.NoClassDefFoundError without any reference to the original problem.

In this case, your configuration might contain errors or is maybe missing altogether?

Upvotes: 4

Related Questions