java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9851528/
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
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
提问by Blue
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.
我已经在线查看了我的问题,我知道它与项目类路径有关。
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.
我在我的项目中添加了一个用户库,其中包含休眠下载中“必需”目录下的所有 jar,但这似乎不起作用。
Please find a screen shot of my project here:
采纳答案by Chris White
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.
您收到错误是因为 Tomcat 无法使用休眠库。在您的图片中,休眠库集下方有一个名为“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)
右键单击您的项目-> 构建路径-> 配置构建路径,然后从构建路径中删除hibernate 设置。现在将 jars 导入到 WEB-INF/lib 文件夹中。刷新您的项目,现在您应该看到它们列在“Web 应用程序库”集中(我很欣赏这有点烦人,因为您必须将它们导入到您的代码库中 - 其他人可能知道这样做的更好方法涉及复制罐子)
回答by Shams
You don't have the hibernate jar present in your library folder Visit the below link for the possible solution, http://www.smashplus.info/2012/11/javalangnoclassdeffounderror.html
您的库文件夹中没有 hibernate jar 请访问以下链接以获取可能的解决方案,http://www.smashplus.info/2012/11/javalangnoclassdeffounderror.html
回答by prageeth
This error can happen when your jar files has not been exportedwith your web archive. You can do what @Chris White has said or you can follow below steps if you are using Eclipse.
当您的 jar 文件未与您的 Web 存档一起导出时,可能会发生此错误。您可以按照@Chris White 所说的进行操作,或者如果您使用的是 Eclipse,则可以按照以下步骤操作。
Right click the project -> Build Path -> Configure Build Path
Right click the project -> Build Path -> Configure Build Path
In the list at left side click on Deployment Assembly. Click "Add" button. Select "Java Build Path Entries" and click next. Now select your hibernate jar files or library. Click finish. Then click Ok.
Restart the server if necessary.
在左侧的列表中单击Deployment Assembly。单击“添加”按钮。选择“ Java Build Path Entries”并单击下一步。现在选择您的休眠 jar 文件或库。单击完成。然后单击确定。
必要时重新启动服务器。
回答by Krishna Choudhary
Simpler way than Chris White's way.
比 Chris White 的方法更简单的方法。
You're getting the error because the hibernate libraries are not available to Tomcat. Right click your project -> Build Path -> Configure Build Path, and removethe hibernate set from the build path.
您收到错误是因为 Tomcat 无法使用休眠库。右键单击您的项目-> 构建路径-> 配置构建路径,然后从构建路径中删除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).
做同样的事情,但不是每次都为新项目导入 jars,**将所需的休眠 jars 复制到 Apache Tomcat 的 lib 文件夹中 **(或任何你使用的服务器)。