休眠 java.lang.NoClassDefFoundError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5664392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:10:28  来源:igfitidea点击:

Hibernate java.lang.NoClassDefFoundError

javahibernateexceptionweb-applications

提问by Muhammad Imran Tariq

I am running a web application with hibernate and got stuck at this exception.

我正在运行一个带有休眠功能的 Web 应用程序,但遇到了这个异常。

    ... 34 more
18:50:02,573 WARN  [AbstractExceptionHandler] Unhandled exception
javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class com.package.util.HibernateUtil
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:295)
    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170).......

采纳答案by JuanZe

Your code is trying to load the definition of com.package.sit.util.HibernateUtilclass but can't find the definition of that class.

您的代码正在尝试加载com.package.sit.util.HibernateUtil类的定义,但找不到该类的定义。

This kind of error is usually related to class loading issues that prevents a JARbeing loaded. Check if you have all required libraries in the CLASSPATH.

这种错误通常与阻止加载JAR 的类加载问题有关。检查CLASSPATH.

回答by ifti

first try to add these .jar slf4j-api.jar and slf4j-log4j12.jar because hibernate internally use these jar.

首先尝试添加这些 .jar slf4j-api.jar 和 slf4j-log4j12.jar 因为 hibernate 内部使用这些 jar。

if it is not working then

如果它不起作用那么

follow these step for netbeans

为 netbeans 执行这些步骤

Step 1. delete project from the netbean but not the original file(Dont check the box which is asking for deleting the project from original location) Step 2. delete dist and build folder form your project folder step 3. create new project with existing source code. step 4. add the required libraries. now built again. now run.

步骤 1. 从 netbean 中删除项目而不是原始文件(不要选中要求从原始位置删除项目的框)步骤 2. 从项目文件夹中删除 dist 和构建文件夹 步骤 3. 使用现有源创建新项目代码。步骤 4. 添加所需的库。现在又建了。现在运行。

i checked it for my project it working for me.

我为我的项目检查了它对我有用。

回答by Withheld

I went through the same exact error (and misleading/useless stack trace) only to discover the solution was very simple:

我经历了完全相同的错误(以及误导/无用的堆栈跟踪),却发现解决方案非常简单:

Copy ojdbc14.jarto %CATALINA_HOME%\lib.

复制ojdbc14.jar%CATALINA_HOME%\lib.

This breakthrough discovery was made possible thanks to this Using Hibernate with Tomcatarticle.

由于这篇使用 Hibernate 与 Tomcat 的文章,这一突破性发现成为可能。

But... if I were more focused, I would have looked way higher at the very beginning of the log:

但是......如果我更专注,我会在日志的最开始看起来更高:

Jan 14, 2013 07:29:17 AM org.hibernate.connection.DriverManagerConnectionProvider configure
SEVERE: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Moral of the story: Sometimes it pays notto look onlyat the point where the exception occurs but rather much much earlier in the log.

这个故事告诉我们:有时候值得只有在这里发生异常,但在日志中较早而很多很多的点。