编译JasperReport时发生了与XML相关的异常 [英] A XML related exception occurred while compiling the JasperReport

查看:140
本文介绍了编译JasperReport时发生了与XML相关的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译我的jasper报告时收到此异常,例外情况是:

I'm getting this exception while compiling my jasper report which the exception is :

net.sf.jasperreports.engine.JRException: org.xml.sax.SAXException: http://java.sun.com/xml/jaxp/properties/schemaSource
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)
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.compileReport(JasperCompileManager.java:143)
at com.mhveranga.siripathi.utill.ReportGenerator.generateOrderInvoice(ReportGenerator.java:50)
at com.mhveranga.siripathi.utill.ReportGenerator.main(ReportGenerator.java:79)
Caused by: org.xml.sax.SAXException: http://java.sun.com/xml/jaxp/properties/schemaSource
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1197)
at org.apache.commons.digester.Digester.parse(Digester.java:1647)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:243)
... 7 more

这是我的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="order" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="294"/>
    <parameter name="custID" class="java.lang.String"/>
    <parameter name="custContact" class="java.lang.String"/>
    <parameter name="custName" class="java.lang.String"/>
    <parameter name="custAddress" class="java.lang.String"/>
    <parameter name="orderID" class="java.lang.String"/>
    <parameter name="mobileBrand" class="java.lang.String"/>
    <parameter name="mobileModel" class="java.lang.String"/>
    <parameter name="mobileIMEI" class="java.lang.String"/>
    <parameter name="isBattery" class="java.lang.String"/>
    <parameter name="isCharger" class="java.lang.String"/>
    <parameter name="isSIM" class="java.lang.String"/>
    <parameter name="isMemory" class="java.lang.String"/>
    <parameter name="description" class="java.lang.String"/>
    <parameter name="note" class="java.lang.String"/>
    <parameter name="date" class="java.lang.String"/>
    <background>
        <band/>
    </background>
    <title>
        <band height="84">
            <staticText>
                <reportElement x="123" y="21" width="297" height="33"/>
                <textElement>
                    <font size="22" isBold="true"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[SIRIPATHI PHONE CENTER]]></text>
            </staticText>
            <line>
                <reportElement x="63" y="54" width="404" height="1"/>
            </line>
        </band>
    </title>
    <pageHeader>
        <band height="109">
            <staticText>
                <reportElement x="203" y="0" width="144" height="20"/>
                <textElement textAlignment="Center">
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Mahawaththe, Batapola]]></text>
            </staticText>
            <staticText>
                <reportElement x="224" y="20" width="103" height="21"/>
                <textElement>
                    <font size="16" isBold="true"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[077 600 1233]]></text>
            </staticText>
            <staticText>
                <reportElement x="203" y="77" width="157" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Software/Hardware/Unlock]]></text>
            </staticText>
            <staticText>
                <reportElement x="27" y="47" width="505" height="30"/>
                <textElement textAlignment="Center">
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[We repair all types of mobile phones in Siripathi Phone Center and we will guarantee all our repairs to be free of defects.]]></text>
            </staticText>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="36"/>
    </columnHeader>
    <detail>
        <band height="512">
            <staticText>
                <reportElement x="38" y="50" width="78" height="23"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Customer ID : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="119" width="90" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Customer Name : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="84" width="100" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Customer Contact : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="152" width="100" height="18"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Customer Address : ]]></text>
            </staticText>
            <line>
                <reportElement x="38" y="193" width="465" height="1"/>
            </line>
            <staticText>
                <reportElement x="38" y="213" width="62" height="16"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Order ID : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="244" width="100" height="17"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Mobile Brand : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="276" width="100" height="18"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Mobile Model : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="307" width="78" height="17"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Mobile IMEI : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="340" width="58" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Battery : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="170" y="340" width="56" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Charger : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="297" y="340" width="41" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[SIM : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="410" y="340" width="50" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Memory : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="372" width="78" height="16"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Description : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="38" y="445" width="58" height="16"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Note : ]]></text>
            </staticText>
            <textField>
                <reportElement x="148" y="50" width="355" height="23"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{custID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="84" width="355" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{custContact}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="119" width="355" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{custName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="152" width="355" height="18"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{custAddress}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="213" width="355" height="16"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{orderID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="244" width="355" height="17"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{mobileBrand}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="276" width="355" height="18"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{mobileModel}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="148" y="307" width="355" height="17"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{mobileIMEI}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="96" y="340" width="48" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{isBattery}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="227" y="340" width="42" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{isCharger}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="338" y="340" width="46" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{isSIM}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="460" y="340" width="52" height="19"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{isMemory}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="144" y="372" width="388" height="54"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{description}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="144" y="445" width="388" height="53"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{note}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="38" y="14" width="78" height="23"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Date :]]></text>
            </staticText>
            <textField>
                <reportElement x="148" y="17" width="355" height="20"/>
                <textElement>
                    <font size="12"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="9"/>
    </columnFooter>
    <pageFooter>
        <band height="9"/>
    </pageFooter>
    <summary>
        <band height="8"/>
    </summary>
</jasperReport>

以下是我在pom.xml中与Jasper相关的依赖项:

Here are my dependencies related to Jasper in my pom.xml :

        <dependency>

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

        <dependency>

            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils-core</artifactId>
            <version>1.8.3</version>

        </dependency>

        <dependency>

            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>

        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging-api</artifactId>
            <version>1.1</version>
        </dependency>


        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>commons-math</groupId>
            <artifactId>commons-math</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>commons-vfs</groupId>
            <artifactId>commons-vfs</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
            <version>1.7</version>
        </dependency>

       <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7.5</version>
        </dependency>

        <dependency>
                <groupId>com.lowagie</groupId>
                <artifactId>itext</artifactId>
                <version>2.1.7</version>
        </dependency>


        <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.0.1-FINAL</version>
        </dependency>

        <dependency>

            <groupId>com.google.code.maven-play-plugin.org.apache.commons</groupId>
            <artifactId>commons-javaflow</artifactId>
            <version>1209105</version>

        </dependency>

这是我的java代码:

This is my java code :

try {
            JasperReport jr = JasperCompileManager.compileReport(reportSource);
            JasperPrint jp = JasperFillManager.fillReport(jr, param);
            JasperViewer.viewReport(jp);
        } catch (JRException ex) {
            Logger.getLogger(ReportGenerator.class.getName()).log(Level.SEVERE, null, ex);
        }

我试了很多才解决这个问题,但我找不到合适的如果您对此有任何疑问,请帮助我。谢谢。

I tried a lot to get this issue solved but i couldn't find proper support please help me if you have any idea about this. Thanks.

推荐答案

我在几天后才发现问题。

I just figured out the issue after trying few days.

最初的问题是我已经将jasperreports依赖的依赖项逐个添加到我的pom中,我不需要这样做。然后出现了冲突。只有jasperreports和groovy依赖就足够了。如果你不使用groovy你也不必添加它。

Initially the issue was that i have added the dependencies which jasperreports depends on one by one manually into my pom which I don't have to do. Then there have been conflicts. Only jasperreports and groovy dependencies are enough. If you don't use groovy you don't have to add that too.

但后来jasperreport说'文件没有页'即使我通过了数据通过参数。那是因为我没有使用

But then later jasperreport said 'The document has no pages' even when I'm passing data through parameters. That is because i haven't used

JasperPrint jp = JasperFillManager.fillReport(jr, param, new JREmptyDataSource());

而不是

JasperPrint jp = JasperFillManager.fillReport(jr, param);

JasperReports没有足够的社区支持我必须自己解决这个问题。无论如何,我建议JasperReports库应该有很大改进。

JasperReports doesn't have enough community support i had to figure this out by my self. Anyway i suggest that JasperReports library should be much improved.

这篇关于编译JasperReport时发生了与XML相关的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆