本文介绍了java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Eclipse 中的 Hibernate 进行初始设置,同时使用 Tomcat 进行部署.

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

我遇到了以下问题:

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.

我在我的项目中添加了一个用户库,其中包含 hibernate 下载中required"目录下的所有 jar,但这似乎不起作用.

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.

请在此处找到我的项目的屏幕截图:

推荐答案

您收到错误是因为 Tomcat 无法使用休眠库.在您的图片中,休眠库集下方有一个名为Web 应用程序库"的空集 - 这是您的休眠库需要位于的集.

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.

右键单击您的项目-> 构建路径-> 配置构建路径,并从构建路径中删除休眠集.现在将 jars 导入到 WEB-INF/lib 文件夹中.刷新您的项目,现在您应该会看到它们列在Web 应用程序库"集中(我知道这有点烦人,因为您必须将它们导入到您的代码库中 - 其他人可能知道一种更好的方法来做到这一点,但没有涉及复制罐子)

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)

这篇关于java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:06
查看更多