【发布时间】:2017-05-24 07:45:03
【问题描述】:
我正在尝试使用 Maven 制作一个简单的 Web 应用程序。运行时,servlet 抛出异常 java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
错误说找不到Hibernate配置文件,虽然依赖是在Maven下添加的。 pom.xml文件如下——(注意依赖hibernate-core v5.2.10.Final)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webapp</groupId>
<artifactId>userinfo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>userinfo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-annotations -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.11.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.11.Final</version>
</dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-tools
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>5.2.0.Final</version>
</dependency> -->
</dependencies>
</project>
我交叉检查,jar 也被添加到“Maven Dependency”选项卡中,并且包含 /cfg/configuration.class。
我不明白可能是什么问题。请建议我怎样才能摆脱错误。
有些东西我已经尝试过了,但都没有奏效:
- 更改了要编译的依赖项。
- 更新(并清理)了 Maven 项目
- 已清理并重新启动 Tomcat 服务器
- 论坛上的一个回答表明使用的 Hibernate 版本之间可能存在冲突。这就是注释“hibernate-tools”依赖项的原因。
任何帮助将不胜感激。谢谢
【问题讨论】:
-
能否手动将
hibernate-core-xxx.Final.jar直接复制到tomcat的lib目录下,以便tomcat在运行时加载。这不是永久修复,只是为了调试。 -
另外,我想知道您是否在
Configuration类周围看到编译错误?
标签: java spring eclipse hibernate maven