1

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?

Marvo
  • 16,808
  • 8
  • 46
  • 69
  • 1
    If you open your built JAR file (can open it using 7-zip/winip/winRar/etc) - can you see the Hibernate JARs listed in your POM in the directory? – rhinds May 22 '11 at 12:47
  • Well, duh, no, they're not. I was so happy that they were listed in the manifest once I got the manifest plugin going, I guess I didn't think to look for the jars in the jar. – Marvo May 22 '11 at 20:38
  • 1
    I'm currently following through on this question about [bundling dependencies in your jar](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven), but your comment pointed me in the right direction. But I'm unable to "accept" a comment, I think. So make it an answer and I'll accept it. – Marvo May 22 '11 at 22:00

1 Answers1

1

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.

rhinds
  • 9,501
  • 12
  • 60
  • 107
  • It did, and thanks. It never occurred to me that the jars wouldn't be packaged up in my project jar. (Makes sense, of course, that it's optional.) And it wasn't as trivial as it seems it should be to get them packaged up, either. But [this other StackOverflow question](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) got me going in that regard. – Marvo May 24 '11 at 00:02