【问题标题】:Maven / Hibernate -- why NoClassDefFoundError on ConstraintViolationException?Maven / Hibernate - 为什么在 ConstraintViolationException 上出现 NoClassDefFoundError?
【发布时间】:2011-05-22 10:33:22
【问题描述】:

我正在使用 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 文件中获得的与休眠相关的最新依赖项。 (在尝试让它工作时,我已经对此进行了几次迭代。)

<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 吗?
  • 嗯,呃,不,他们不是。一旦我启动了清单插件,我很高兴它们被列在清单中,我想我没想到在罐子里寻找罐子。
  • 我目前正在跟进这个关于bundling dependencies in your jar 的问题,但您的评论为我指明了正确的方向。但我认为,我无法“接受”评论。所以让它成为一个答案,我会接受它。

标签: java hibernate maven


【解决方案1】:

如果您打开构建的 JAR 文件(可以使用 7-zip/winip/winRar/etc 打开它) - 检查您是否可以在目录中的 POM 中看到列出的 Hibernate JAR。

很高兴它帮助您指明了正确的方向。

【讨论】:

  • 成功了,谢谢。我从来没有想过这些罐子不会被打包到我的项目罐子里。 (当然,这是有道理的,它是可选的。)而且将它们打包也并不像看起来那么简单。但是this other StackOverflow question 让我在这方面有所进步。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-02
  • 2012-09-15
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多