Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasper reports barcode using style-Barcode

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)
like image 678
Toral Avatar asked Aug 23 '12 07:08

Toral


People also ask

What is Jasper and Jrxml?

jrxml is a human readable XML file that contains the report template i.e. report structure and its formatting rules. . jasper is the compiled report template i.e. compiled . jrxml file. You use this file as the template argument in the JasperReports API.

Is Jasper a reporting tool?

JasperReports is an open source Java reporting tool that can write to a variety of targets, such as: screen, a printer, into PDF, HTML, Microsoft Excel, RTF, ODT, comma-separated values (CSV) or XML files. It can be used in Java-enabled applications, including Java EE or web applications, to generate dynamic content.


1 Answers

You should add library batik-bridge:

<dependency>
    <groupId>batik</groupId>
    <artifactId>batik-bridge</artifactId>
    <version>1.6-1</version>
</dependency>
like image 114
Marcin Erbel Avatar answered Oct 26 '22 15:10

Marcin Erbel