jasper使用style-Barcode报告条形码

时间:2012-08-23 07:52:46

标签: jasper-reports

我正在尝试在 JasperReports 中使用条形码我正在使用 barcode4j jar。 我正在使用的罐子是:

  • barcode4j-2.0.jar
  • commons-beanutils.jar
  • commons-codec-1.6.jar
  • commons-collections.jar
  • commons-digester-2.0.jar
  • commons-lang-2.0.jar
  • commons-logging.jar
  • commons-net-1.2.2.jar
  • commons-validator.jar
  • db2jcc.jar
  • db2jcc_license_cu.jar
  • itext-2.1.7.jar
  • jasperreports-4.5.0.jar
  • log4j-1.2.8.jar
  • POI-3.8-20120326.jar

我正在使用条形码的 jrxml 文件内容如下所示:

<title>    
    <band height="125">    
        <frame>    
            <reportElement x="0" y="0" width="555" height="40" />    
            <componentElement>    
                <reportElement style="Barcode" x="5" y="5" width="400" height="30"/>    
                <c:Code39 xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"    xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components    http://jasperreports.sourceforge.net/xsd/components.xsd">    
                    <c:codeExpression>$F{OPA_ACK_NO_PK}</c:codeExpression>    
                </c:Code39>    
            </componentElement>    
        </frame>    
    </band>    
</title>

但是我收到以下错误:

net.sf.jasperreports.engine.JRRuntimeException: Could not resolve style(s): Barcode4j
at net.sf.jasperreports.engine.fill.JRFillObjectFactory.checkUnresolvedReferences(JRFillObjectFactory.java:1577)
at net.sf.jasperreports.engine.fill.JRFillObjectFactory.setStyles(JRFillObjectFactory.java:1504)
at net.sf.jasperreports.engine.fill.JRBaseFiller.loadStyles(JRBaseFiller.java:912)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:804)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:746)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
at Report.Test.main(Test.java:162)

请指导我做错了什么?

删除条形码样式标记的注释后,我摆脱了该错误并得到了另一个例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/batik/bridge/UserAgent
    at net.sf.jasperreports.components.barcode4j.BarcodeSVGImageProducer.createImage(BarcodeSVGImageProducer.java:69)
    at net.sf.jasperreports.components.barcode4j.BarcodeFillComponent.setBarcodeImage(BarcodeFillComponent.java:149)
    at net.sf.jasperreports.components.barcode4j.BarcodeFillComponent.fill(BarcodeFillComponent.java:113)
    at net.sf.jasperreports.engine.fill.JRFillComponentElement.fill(JRFillComponentElement.java:148)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.fillElements(JRFillElementContainer.java:570)
    at net.sf.jasperreports.engine.fill.JRFillFrame.fill(JRFillFrame.java:276)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.fillElements(JRFillElementContainer.java:570)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:406)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:352)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVerticalFiller.java:323)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:257)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:836)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:746)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at Report.Test.main(Test.java:169)

我添加了所需的蜡染,深红色,xerces和xercesImpl罐子。但我收到以下错误:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.apache.batik.bridge.ViewBox.getPreserveAspectRatioTransform([FSZFF)Ljava/awt/geom/AffineTransform; from class net.sf.jasperreports.renderers.BatikRenderer
    at net.sf.jasperreports.renderers.BatikRenderer.render(BatikRenderer.java:123)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1405)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:757)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportFrame(JRPdfExporter.java:2554)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:765)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:721)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:635)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:383)
    at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:122)
    at Report.Test.main(Test.java:172)

3 个答案:

答案 0 :(得分:7)

你应该添加库batik-bridge:

<dependency>
    <groupId>batik</groupId>
    <artifactId>batik-bridge</artifactId>
    <version>1.6-1</version>
</dependency>

答案 1 :(得分:2)

昨天我遇到了完全相同的问题,我成功解决了以下问题:

        <componentElement>
            <reportElement x="311" y="166" width="180" height="10"/>
            <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code39 (Extended)" drawText="false" checksumRequired="false">
                <jr:codeExpression><![CDATA[$P{barcode}]]></jr:codeExpression>
            </jr:barbecue>
        </componentElement>

答案 2 :(得分:1)

对我来说,将batik-bridge添加到项目pom.xml以下的依赖关系:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>batik-bridge</artifactId>
    <version>1.9.1</version>
</dependency>