3

我们使用iReport4.5.1创建了报告。它在iReport中正常工作。

之后,我们将报告集成到我们的应用程序中。我们使用 maven 构建我们的应用程序。以下是pom.xml中的JasperReports依赖项

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>4.5.1</version>
</dependency>

<dependency>
    <groupId>jasperreports-javaflow</groupId>
    <artifactId>jasperreports-javaflow</artifactId>
    <version>4.5.1</version>
</dependency>

以下是生成报告的Java代码:

String jrxmlFilePath = getConfigBundle().getString("jasper.templates.jrxml.path");
String jasperFilePath = getConfigBundle().getString("jasper.templates.jasper.path");
JasperCompileManager.compileReportToFile(jrxmlFilePath, jasperFilePath);
File jasperFile = new File(jasperFilePath);
Connection conn = setUpDataSource();
HashMap jasperParameter = setUpJasperParameterForPackingList(truckId, rackId, jasperFile);
JasperPrint jprint = JasperFillManager.fillReport(jasperFilePath, jasperParameter, conn);
ByteArrayOutputStream reportOutputStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jprint, reportOutputStream);
return reportOutputStream;

当我调用此代码时,它会给我以下错误:

ERROR - [DGU_ACTION_SERVLET] ServletException
javax.servlet.ServletException: net.sf.jasperreports.engine.JRRuntimeException: Error creating SAX parser
    at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at com.saintgobain.dgu.mvc.action.DguActionServlet.process(DguActionServlet.java:41)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: Error creating SAX parser
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:99)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1342)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1318)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:108)
    at com.saintgobain.dgu.helper.ExportReportPDFHelper.printPackingListJasper(ExportReportPDFHelper.java:287)
    at com.saintgobain.dgu.helper.ExportReportPDFHelper.generatePDF4PackingList(ExportReportPDFHelper.java:353)
    at com.saintgobain.dgu.mvc.action.shipping.ExportShippingReportAction.execute(ExportShippingReportAction.java:79)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    ... 22 more
Caused by: org.xml.sax.SAXNotRecognizedException: Property: http://java.sun.com/xml/jaxp/properties/schemaLanguage
    at org.apache.crimson.parser.XMLReaderImpl.setProperty(XMLReaderImpl.java:266)
    at org.apache.crimson.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.configureParser(BaseSaxParserFactory.java:132)
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:94)
    ... 32 more
ERROR - [DGU_ACTION_SERVLET] ServletException - root cause
net.sf.jasperreports.engine.JRRuntimeException: Error creating SAX parser
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:99)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1342)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1318)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:108)
    at com.saintgobain.dgu.helper.ExportReportPDFHelper.printPackingListJasper(ExportReportPDFHelper.java:287)
    at com.saintgobain.dgu.helper.ExportReportPDFHelper.generatePDF4PackingList(ExportReportPDFHelper.java:353)
    at com.saintgobain.dgu.mvc.action.shipping.ExportShippingReportAction.execute(ExportShippingReportAction.java:79)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at com.saintgobain.dgu.mvc.action.DguActionServlet.process(DguActionServlet.java:41)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.xml.sax.SAXNotRecognizedException: Property: http://java.sun.com/xml/jaxp/properties/schemaLanguage
    at org.apache.crimson.parser.XMLReaderImpl.setProperty(XMLReaderImpl.java:266)
    at org.apache.crimson.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.configureParser(BaseSaxParserFactory.java:132)
    at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:94)
    ... 32 more
  1. 我们使用iReportJasperReports版本作为 4.5.1
  2. 我已将XercesImpl.jar(2.8.1 版)依赖项放在类路径中
  3. 我们正在使用Jdk.1.6.0_33

请帮助我如何消除这个错误?

4

1 回答 1

2

从堆栈跟踪的这一行可以看出:

org.apache.crimson.parser.XMLReaderImpl.setProperty(XMLReaderImpl.java:266)

在您的应用程序中使用Crimson XML解析器。

Crimson实现不支持不同于这些值[1]的属性值:

"http://xml.org/sax/properties/lexical-handler"

"http://xml.org/sax/properties/declaration-handler"

但是JasperReports引擎尝试使用属性(从堆栈跟踪[2]http://java.sun.com/xml/jaxp/properties/schemaLanguage中可以看到)。

iReport使用Xerces XML解析器实现。例如,iReport 4.7.0iReport 5.2.0使用的是2.8.0版本的Xerces

您可以尝试将此 ( Xerces ) 库添加到pom.xml作为依赖项。

备注

[1]:参见org.apache.crimson.parser.XMLReaderImpl类中方法getProperty(String)的源代码

[2]:JR引擎尝试在方法中为SAXParsernet.sf.jasperreports.engine.xml.BaseSaxParserFactory.configureParser(SAXParser)设置此属性。

于 2013-07-18T12:52:28.960 回答