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&l开发者_JAVA技巧t;/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?
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.
精彩评论