1
我的任務是遷移使用Apache FOP 1.1的舊Java應用程序。我想使用最新的FOP版本2.1,但是在設置FOP的代碼中遇到問題。Apache FOP 1.1> 2.1遷移
這裏是我們的原代碼,使用1.1 API:
FopFactory fopFactory = FopFactory.newInstance();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ConfigurationDataUtility configurationData = new ConfigurationDataUtility();
try
{
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
下面是新的代碼,使用2.1 API:
InputStream is = getClass().getClassLoader().getResourceAsStream("fop.xconf");
FopConfParser parser = new FopConfParser(is, new java.net.URI(".")); //parsing configuration
FopFactoryBuilder builder = parser.getFopFactoryBuilder(); //building the factory with the user options
FopFactory fopFactory = builder.build();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ConfigurationDataUtility configurationData = new ConfigurationDataUtility();
try
{
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
可悲的是,FOP上具有非常小的文件其網站和什麼是主要爲版本1.1。上面的代碼是從他們的頁面的目錄中獲取的,該部分說明如何從1.1遷移到2.1,所以我認爲它是正確的。
https://xmlgraphics.apache.org/fop/2.1/upgrading.html
的問題是執行這個新的代碼時,下面的異常對構建新FopConfParser行拋出:
Caused by: java.lang.Error: Unable to setup SAX parserjava.lang.ClassCastException: __redirected.__SAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory
at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder.<init>(DefaultConfigurationBuilder.java:112)
at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder.<init>(DefaultConfigurationBuilder.java:83)
at org.apache.fop.apps.FopConfParser.<init>(FopConfParser.java:146)
at org.apache.fop.apps.FopConfParser.<init>(FopConfParser.java:88)
at org.apache.fop.apps.FopConfParser.<init>(FopConfParser.java:103)
at xmltools.PDFGenerator.generatePDF(PDFGenerator.java:73)
at defect.DefectServlet.generateDefectPrintablePdf(DefectServlet.java:703)
... 35 more
我們正在運行Wildfly 9作爲我們的服務器。因此,我已經添加了,因爲我得到ClassNotFound的異常沒有他們下面以FOP的module.xml文件:
<dependencies>
<module name="org.apache.avalon" />
<module name="org.xml.sax" />
<module name="org.apache.xmlgraphics" />
</dependencies>
我已經添加了以下到我的JVM啓動,希望它有助於瞭解更多的光在情況,但它沒有:
-Djaxp.debug=1
我一直在尋找這3天的更好的一部分,現在沒有取得進展。任何建議將不勝感激。
謝謝。