1. 程式人生 > >異常記錄 之 nested exception is java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte

異常記錄 之 nested exception is java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte

nested exception is java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte

在MVC 整合jasperreport 的時候.遇到一個問題,老是報 java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte,

檢視自己的maven依賴.顯示已經添加了對應的依賴.經過很久的查詢,在jasperReport官網找到一個原因.

說是jasperReport 的依賴只和 itext的 2.1.7 版本相容.不相容其他版本.所以在我們編譯過程中不會遇到問題.但是一旦呼叫方法就報錯;;

大家也注意一下 是NoClassDef  而不是NoClassFound  ,這兩者不一樣;

OK !! 

我把我的依賴添一下.方便大家遇到同樣的問題.可以找到問題的根源

        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.1.7</version>
        </dependency>

原本我的Itext 的版本是4.* 的.版本衝突很不容易發現.讓人很惱火.可能很久找不到原因....
希望我的記錄對於同時在學習Jasperreport 整合MVC的人們又所幫助!