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天的更好的一部分,现在没有取得进展。任何建议将不胜感激。
谢谢。