简体   繁体   English

java.lang.NoClassDefFoundError: org/hibernate/cfg/配置

[英]java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

I'm trying to do an initial setup with Hibernate in Eclipse, while deploying with Tomcat.我正在尝试使用 Eclipse 中的 Hibernate 进行初始设置,同时使用 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.我在网上查看了我的问题,我知道它与项目 class 路径有关。

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.我已经在我的项目中添加了一个用户库,其中包含 hibernate 下载中“必需”目录下的所有 jars,但这似乎不起作用。

Please find a screen shot of my project here:在此处找到我的项目的屏幕截图:

You're getting the error because the hibernate libraries are not available to Tomcat. 您收到错误是因为Tomcat无法使用hibernate库。 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. 在你的图片中,在hibernate库集下面有一个名为“Web App Libraries”的空集 - 这是你的hibernate库需要的集合。

Right click your project -> Build Path -> Configure Build Path, and remove the hibernate set from the build path. 右键单击您的项目 - >构建路径 - >配置构建路径,然后从构建路径中删除hibernate集。 Now import the jars into the WEB-INF/lib folder. 现在将jar导入WEB-INF / lib文件夹。 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) 刷新你的项目,现在你应该看到它们列在'Web App Libraries'集中(我很感激你有点讨厌,你必须将它们导入你的代码库 - 其他人可能知道一个更好的方法来做到这一点不涉及复制罐子)

This error can happen when your jar files has not been exported with your web archive. 当您的jar文件尚未与Web存档一起导出时,可能会发生此错误。 You can do what @Chris White has said or you can follow below steps if you are using Eclipse. 您可以执行@Chris White所说的内容,或者如果您使用的是Eclipse,则可以按照以下步骤操作。

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

In the list at left side click on Deployment Assembly . 在左侧列表中,单击Deployment Assembly Click " Add " button. 单击“ 添加 ”按钮。 Select " Java Build Path Entries " and click next . 选择“ Java Build Path Entries ”,然后单击“ 下一步” Now select your hibernate jar files or library. 现在选择你的hibernate jar文件或库。 Click finish . 点击完成 Then click Ok . 然后单击确定
Restart the server if necessary. 必要时重启服务器。

Simpler way than Chris White's way. 比克里斯怀特更简单的方式。

You're getting the error because the hibernate libraries are not available to Tomcat. 您收到错误是因为Tomcat无法使用hibernate库。 Right click your project -> Build Path -> Configure Build Path, and remove the hibernate set from the build path. 右键单击您的项目 - >构建路径 - >配置构建路径,然后从构建路径中删除 hibernate集。

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). 做同样的事情,但不是每次为新项目导入jar,**复制Apache Tomcat **的lib文件夹中所需的hibernate jar(或者你正在使用的服务器)。

您的库文件夹中没有hibernate jar请访问以下链接以获取可能的解决方案, http://www.smashplus.info/2012/11/javalangnoclassdeffounderror.html

To achieve the same with IntelliJ:要使用 IntelliJ 实现相同的目的:

  • File -> Project Structure文件 -> 项目结构
  • Project Settings -> Artifacts项目设置 -> 工件
  • Select your.war artifact Select your.war神器
  • expand Available Elements展开可用元素
  • right click the Hibernate lib -> Put into /WEB-INF/lib右击 Hibernate 库 -> 放入 /WEB-INF/lib

Done.完毕。

暂无
暂无

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

相关问题 MultiException堆栈1 of 2 java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration - MultiException stack 1 of 2 java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration 线程“ main”中的异常java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration - Exception in thread “main” java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration 注入自动连接的依赖项失败; 嵌套异常是java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration - Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration java.lang.NoClassDefFoundError:org / hibernate / cfg / AnnotationConfiguration - java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration 在一个简单的 maven hibernate 项目中得到错误“java.lang.NoClassDefFoundError: org/hibernate/cfg/Mappings” - getting error “java.lang.NoClassDefFoundError: org/hibernate/cfg/Mappings” in a simple maven hibernate project java.lang.NoClassDefFoundError:无法初始化类org.hibernate.cfg.AnnotationConfiguration - java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.AnnotationConfiguration java.lang.NoClassDefFoundError:org / hibernate / MappingException - java.lang.NoClassDefFoundError: org/hibernate/MappingException 无法创建sessionFactory object.java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration - Failed to create sessionFactory object.java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration Java Web应用程序中的Hibernate NoClassDefFoundError org.hibernate.cfg.Configuration - Hibernate NoClassDefFoundError org.hibernate.cfg.Configuration in Java web application java.lang.NoClassDefFoundError: 无法初始化类 org.hibernate.ejb.Ejb3Configuration - java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM