2011-05-22 140 views
1

我正在使用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> 

我要離開什麼?

+1

如果你打開你的內置JAR文件(可以使用7-zip/winip/winRar/etc打開它) - 你可以在目錄中看到POM中列出的Hibernate JAR文件嗎? – rhinds 2011-05-22 12:47:42

+0

呃,不,他們不是。我很高興他們被列入清單中,一旦我得到了明顯的插件,我想我沒有想到在罐子裏尋找罐子。 – Marvo 2011-05-22 20:38:28

+1

我目前正在通過關於[捆綁在你的jar中的依賴關係]這個問題(http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using -maven),但你的評論指出我的方向是正確的。但我想,我無法「接受」評論。所以,讓它成爲答案,我會接受它。 – Marvo 2011-05-22 22:00:46

回答

1

如果您打開已構建的JAR文件(可以使用7-zip/winip/winRar/etc打開它) - 請檢查您是否可以在目錄中看到POM中列出的Hibernate JAR。

很高興幫助您指出正確的方向。

+0

它做到了,謝謝。我從來沒有想到,罐子不會被包裝在我的項目罐子裏。 (當然,這是有道理的,它是可選的)。它看起來應該是將它們打包起來也不是微不足道的。但[此其他StackOverflow問題](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven)讓我在這方面。 – Marvo 2011-05-24 00:02:41