jasper reports barcode using style-Barcode
jasper-reports
Solution
You should add library batik-bridge:
<dependency>
<groupId>batik</groupId>
<artifactId>batik-bridge</artifactId>
<version>1.6-1</version>
</dependency>
Problem
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) ```