5
votes

I am trying to use barcode in JasperReports for which I am using the barcode4j jar. The jars that i am using are:

  • 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

The jrxml file content where I am using barcode is as given below:

<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>

But I am getting the following error:

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)

Please guide me as to what am I doing wrong?

After removing the comment for Barcode style tag, i got rid of that error and got another exception:

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)

I added the required batik, crimson, xerces and xercesImpl jars. But I am getting the following error:

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
Did you check the Barcode4j style declaration in your report? You can try to remove style reference for Barcode component - Alex K
Thank you Alex from ur prompt help.. I had actually commented the barcode style in my jrxml.. - Toral
Alex, i couldnt answer to this question right now.. so i have edited the question.. please have a look at the same.. - Toral
Can it be due to some deprecated method being called?? - Toral
You should compare libraries versions with ones from JR's pom.xml - Alex K

3 Answers

7
votes

You should add library batik-bridge:

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

Yesterday i had exactly the same problem, i succeded to resolve it by using:

        <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>
1
votes

For me adding batik-bridge with below dependency to project pom.xml worked:

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