简体   繁体   English

NoClassDefFoundError

[英]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. 请帮助我解决此问题,我已经在Web应用程序的lib文件夹中添加了所有必需的休眠jar文件。

now what should i do? 现在我该怎么办?

I suspect you're missing a log4j jar or a commons-logging.jar. 我怀疑您缺少log4j jar或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 . 消息Could not initialize class org.hibernate.cfg.Configuration表示JVM已经尝试并且无法初始化类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. 由于此字段被标记为static ,因此在初始化类后会设置该字段的值。 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. 该字段是此类的唯一静态成员,因此,如果JVM无法初始化此类,则此字段一定存在问题。

java.lang.NoClassDefFoundError is a tricky exception. java.lang.NoClassDefFoundError是一个棘手的异常。 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. 当首次访问此类时遇到此问题(并且在这里报告了根本问题)时,这尤其麻烦,但是对此类的后续访问只会吐出可怕的java.lang.NoClassDefFoundError而没有任何对原始问题的引用。

In this case, your configuration might contain errors or is maybe missing altogether? 在这种情况下,您的配置可能包含错误,或者可能完全丢失?

What arjan said. 阿尔扬说了什么。 The error you are having doesn't say that it cannot find cfg.Configuration. 您遇到的错误并不表示找不到cfg.Configuration。 It simply says that somewhere in the initialization of cfg.Configuration, a class definition was not found. 它只是说在cfg.Configuration初始化的某个地方,找不到类定义。 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. 在我看来这是类cfg.Configuration依赖于应用程序的WEB-INF / lib目录中缺少的类。

Take a look at this thread in the Spring Forums, they seem to talk about the problem you are having: 在Spring论坛中看看这个线程,他们似乎在谈论您遇到的问题:

http://forum.springsource.org/showthread.php?t=65296 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): 特别值得一提的是,其中一位资深成员发表的帖子中提到了另外四个遗漏的jar(请注意,这是在2008年,我不知道您使用的冬眠和春季版本):

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

Hope it helps. 希望能帮助到你。

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. 正如Luke Woodward所指出的那样,我只是在使用Hibernate 3.5.4('java.lang.NoClassDefFoundError:无法初始化org.hibernate.cfg.AnnotationConfiguration')时收到了非常类似的异常消息,它与日志记录有关。 So I would guess that you are missing a slf4j implementation with its corresponding dependencies. 因此,我想您会丢失一个具有相应依赖项的slf4j实现。

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. luis.espinal提供的链接( http://forum.springsource.org/showpost.php?s=f3b5de4e9df29e65d4c9a​​caafc1676c8&p=219678&postcount=10 )指出您可能缺少的JAR。 Among them is slf4j-log4j12-1.5.0.jar . 其中是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: 最重要的是,在线hibernate文档的“第一个Hibernate应用程序”教程中的pom.xml包含对slf4j实现的明确引用:

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

I was using the Ant Maven Tasks and my problem was solved adding the dependency to slf4j-log4j12. 我正在使用Ant Maven任务,并且我的问题已解决,将依赖项添加到slf4j-log4j12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM