简体   繁体   English

Jasper报告生成错误

[英]Error in Jasper Report Generation

I have designed a JRXML on Jaspersoft Studio 5.1.0, able to generate a CSV format report on Eclipse and Windows machine. 我在Jaspersoft Studio 5.1.0上设计了一个JRXML,能够在Eclipse和Windows机器上生成CSV格式报告。 When i export the java code onto Unix server, getting below error. 当我将java代码导出到Unix服务器上时,得到以下错误。

Java Version of Unix Server : "1.7.0.08" Unix服务器的Java版本:“1.7.0.08”

Caused by: java.lang.ExceptionInInitializerError
        at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
        at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
        at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:148)
        at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:861)
        at com.infy.ui.mig.compare.MigrationUXAndONSCompare.GenerateReport(MigrationUXAndONSCompare.java:518)
        ... 2 more
Caused by: net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: Problem reading font data.
        at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:182)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFace(SimpleFontExtensionHelper.java:364)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:290)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamilies(SimpleFontExtensionHelper.java:254)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:215)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:184)
        at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:110)
        at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
        ... 11 more
Caused by: java.io.IOException: Problem reading font data.
        at java.awt.Font.createFont0(Font.java:999)
        at java.awt.Font.createFont(Font.java:876)
        at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:174)
        ... 19 more

Java Code : Java代码:

JasperPrint jasperPrint;
            JasperReport jasperReport;
            HashMap jasperParams = new HashMap();

            InputStream input = new FileInputStream(jrxmlFile);
            JasperDesign design = JRXmlLoader.load(input);
            jasperReport = JasperCompileManager.compileReport(design);
            jasperReport.isIgnorePagination();
            Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(writeFileDir));

            jasperParams.put(jasperReport.isIgnorePagination(), Boolean.TRUE);
            jasperParams.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
            jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParams);

            JRCsvExporter exporter = new JRCsvExporter();
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, csvReportName);
            exporter.exportReport();

JRXML File : JRXML文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="HCOTA_RTACOF" language="groovy" pageWidth="3500" pageHeight="4000" columnWidth="3460" columnSpacing="37" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="b857e321-5d0f-4309-a5f5-950316db1f9d">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="XmlDataSource_HRDM_ARD"/>
    <subDataset name="Dataset1" uuid="62525010-7a4a-47a7-b029-c7502b171ae9">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="field_name" class="java.lang.String">
            <fieldDescription><![CDATA[@name]]></fieldDescription>
        </field>
        <field name="group-name-ons" class="java.lang.String">
            <fieldDescription><![CDATA[field-type[@type = "ons"]/group-name]]></fieldDescription>
        </field>
        <field name="page-name-ons" class="java.lang.String">
            <fieldDescription><![CDATA[field-type[@type = "ons"]/page-name]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="XPath">
        <![CDATA[/menu-compare/field-details/fields]]>
    </queryString>
    <field name="field_exists" class="java.lang.String">
        <fieldDescription><![CDATA[@existence]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="82" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="120" splitType="Immediate">
            <printWhenExpression><![CDATA[$V{PAGE_NUMBER}==1]]></printWhenExpression>
            <textField>
                <reportElement uuid="78cd7b95-378a-47a7-a2e6-635677759067" x="10" y="60" width="70" height="30" backcolor="#FFFFFF"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Map Type"]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement uuid="a11ecb4a-06f1-400f-953f-e39edbcf3d9f" isPrintRepeatedValues="false" x="80" y="60" width="70" height="30"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Back End Field"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="40a166e8-1aa0-45e8-a10c-ecf61f6b2f5a" x="150" y="60" width="70" height="30"/>
                <textElement>
                    <font isBold="true" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <textFieldExpression><![CDATA["Group Name"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="c19e0438-7cf9-499e-80d4-7e2f8caaa54b" x="220" y="60" width="70" height="30"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Page Name"]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <componentElement>
                <reportElement uuid="f80aa2dd-1bdd-41fe-82f2-59b4e56d4b28" x="10" y="40" width="1760" height="60"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
                    <datasetRun subDataset="Dataset1" uuid="c1fe8920-0512-41bc-9f79-8fcbc61ac067">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/fields/field")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="125" width="1760">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="8d3ab036-d155-4f07-9345-dd37dd3f7101" x="70" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{field_name}]]></textFieldExpression>
                        </textField>
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="575757aa-2b24-446e-aa79-ea0c5eb02049" x="140" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{group-name-ons}]]></textFieldExpression>
                        </textField>
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="09512867-0754-4544-991f-8dd4ffc7d8c6" x="210" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{page-name-ons}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="fd3813e4-e26d-48ec-8519-c2c25780f48c" x="10" y="55" width="70" height="30"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{field_exists}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

I think pdfFontName="Helvetica-Bold" is causing the problem. 我认为pdfFontName="Helvetica-Bold"导致了这个问题。 There are two things to consider here. 这里有两件事需要考虑。

  1. When you are exporting your report and want Helvetica-Bold to appear in it, then you'll to create font-extension for it, unless your JVM already as Helvetica-Bold with it. 当您导出报告并希望Helvetica-Bold出现在其中时,您将为它创建字体扩展名,除非您的JVM已经与Helvetica-Bold一起使用它。
  2. You would have to create custom styles in the jrxml file and use fonts there and apply style to elements in case of using font extension. 您必须在jrxml文件中创建自定义样式并在那里使用字体,并在使用字体扩展名时将样式应用于元素。

Hope this helps you. 希望这对你有所帮助。

Just seeing your exception stack trace... it says 只是看到你的异常堆栈跟踪......它说

Caused by: java.io.IOException: Problem reading font data.

Probably in your JRXML template you might be using some font which is not available in your application 可能在您的JRXML模板中,您可能正在使用某些在您的应用程序中不可用的字体

I have been trying to figure out a similar problem since yesterday, and finally found an answer that fixed the problem for me (please see the link below) . 自从昨天以来我一直试图弄清楚类似的问题,最后找到了解决问题的答案(请参阅下面的链接) This was only happening in our QA environment, but not on my local desktop machine. 这只发生在我们的QA环境中,而不是在我的本地桌面计算机上。

Shortly, the error message is pretty misleading and the actual problem is java.awt.Front not being able to write the Java-temp-directory (java.io.tmpdir) as described in the original answer below. 很快,错误消息非常误导,实际问题是java.awt.Front not being able to write the Java-temp-directory (java.io.tmpdir) ,如下面的原始答案中所述。 All I had to do is create a Tomcat temp directory manually (which was never created before in QA environment). 我所要做的就是手动创建一个Tomcat临时目录(以前从未在QA环境中创建过)。 After that, it just started working fine. 在那之后,它刚刚开始正常工作。

Original answer that I found 我找到的原始答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM