我正在使用Maven構建這個Hibernate應用程序。它在Eclipse中運行的方式(使用Maven插件)。但是,當我從命令行「mvn clean install」jar文件,然後嘗試使用java -jar target/JarFileName.jar在jar中運行程序時,該應用程序最終將與:Maven/Hibernate - 爲什麼NoClassDefFoundError出現ConstraintViolationException?
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文件嗎? – rhinds 2011-05-22 12:47:42
呃,不,他們不是。我很高興他們被列入清單中,一旦我得到了明顯的插件,我想我沒有想到在罐子裏尋找罐子。 – Marvo 2011-05-22 20:38:28
我目前正在通過關於[捆綁在你的jar中的依賴關係]這個問題(http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using -maven),但你的評論指出我的方向是正確的。但我想,我無法「接受」評論。所以,讓它成爲答案,我會接受它。 – Marvo 2011-05-22 22:00:46