我试图在JasperReports中使用条形码,而我正在使用条形码4j jar。
我正在使用的罐子是:
条码4j-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)
最佳答案
您应该添加库蜡染桥:
<dependency>
<groupId>batik</groupId>
<artifactId>batik-bridge</artifactId>
<version>1.6-1</version>
</dependency>