我正在使用 Maven 构建这个 Hibernate 应用程序。它按照我在 Eclipse 中期望的方式运行(使用 Maven 插件)。但是当我从命令行“mvn clean install”jar 文件,然后尝试使用 java -jar target/JarFileName.jar 运行 jar 中的程序时,应用程序最终会终止:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/exception/ConstraintViolationException
我在 .m2 目录的 hibernate jar 中看到了该类。
这是我在 POM 文件中获得的最新的 hibernate 相关依赖项。 (在尝试让它发挥作用的过程中,我对此进行了几次迭代。)
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.3.GA</version>
<scope>test</scope>
</dependency>
我遗漏了什么?
最佳答案
如果您打开构建的 JAR 文件(可以使用 7-zip/winip/winRar/etc 打开它) - 检查您是否可以在目录中的 POM 中看到列出的 Hibernate JAR。
很高兴它帮助您指明了正确的方向。
关于java - Maven/Hibernate——为什么在 ConstraintViolationException 上出现 NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6087355/