You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JasperSoft Studio二维码编译报错:MatrixToImageWriter无法解析

问题描述

重新安装JasperSoft Studio后,含二维码的报表无法编译,报错com.google.zxing.client.j2se.MatrixToImageWriter cannot be resolved to a type,详细错误信息如下:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
    1. com.google.zxing.client.j2se.MatrixToImageWriter cannot be resolved to a type
                    value = com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage( //$JR_EXPR_ID=38$
                            <---------------------------------------------->
    2. com.google.zxing.client.j2se.MatrixToImageWriter cannot be resolved to a type
                    value = com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage( //$JR_EXPR_ID=38$
                            <---------------------------------------------->
    3. com.google.zxing.client.j2se.MatrixToImageWriter cannot be resolved to a type
                    value = com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage( //$JR_EXPR_ID=38$
                            <---------------------------------------------->
    3 errors
    .

        at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:229)

        at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:289)

        at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:141)

        at net.sf.jasperreports.eclipse.builder.JasperReportsBuilder.compileJRXML(JasperReportsBuilder.java:212)

        at com.jaspersoft.studio.editor.action.CompileAction.actionCompile(CompileAction.java:154)

        at com.jaspersoft.studio.editor.action.CompileAction$1.run(CompileAction.java:98)

        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

报表中生成二维码的表达式为:

com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(
    new com.google.zxing.qrcode.QRCodeWriter().encode(
        $F{QRCODE},
        com.google.zxing.BarcodeFormat.QR_CODE, 400, 400
    )
)

已尝试配置Eclipse的Java Build Path并添加ZXing的Core和JavaSE jar包,但问题依旧。

解决方案

核心原因是JasperSoft Studio编译报表时使用的是自身专属类加载路径,而非Eclipse项目的Build Path,按以下步骤排查:

  • 确保ZXing版本与生产环境完全一致
    生产环境能正常运行说明版本匹配,本地必须使用相同版本的ZXing Core和JavaSE jar包,不同版本可能存在类结构变动,导致找不到目标类。

  • 配置JSS专属的报表类路径

    1. 在JSS中右键点击目标报表文件,选择Properties
    2. 切换到JasperReports Classpath选项卡
    3. 点击Add External JARs,选中你的ZXing Core和JavaSE jar包,添加完成后点击Apply and Close
  • 手动复制jar到JSS安装目录(备选方案)
    如果上述配置无效,直接将ZXing的两个jar包复制到JSS安装目录下的plugins/com.jaspersoft.studio.report_<具体版本号>/lib文件夹,然后重启JSS。

  • 清理缓存并重新编译

    1. 右键点击项目,选择Clean
    2. 删除报表生成的.jasper编译文件
    3. 重新点击编译按钮执行编译

内容的提问来源于stack exchange,提问作者Thomas Carlton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 19:35:23