Maven / Hibernate——为什么在 ConstraintViolationException 上出现 NoClassDefFoundError?
我正在使用 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>
我遗漏了什么?
I'm building this Hibernate application using Maven. It runs the way I expect in Eclipse (using a Maven plugin.) But when I "mvn clean install" the jar file from the command line, and then try to run the program in the jar with java -jar target/JarFileName.jar, the application eventually dies with:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/exception/ConstraintViolationException
I see the class in the hibernate jar in the .m2 directory.
Here's the latest hibernate-related dependencies I've got in my POM file. (I've been through a few iterations on this while trying to get it to work.)
<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>
What am I leaving out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您打开构建的 JAR 文件(可以使用 7-zip/winip/winRar/etc 打开它) - 检查您是否可以在目录中的 POM 中看到列出的 Hibernate JAR。
很高兴它帮助您指明了正确的方向。
If you open your built JAR file (can open it using 7-zip/winip/winRar/etc) - check if you can see the Hibernate JARs listed in your POM in the directory.
Glad it helped point you in the right direction.