在使用Adopt OpenJDK 11编译Jasper Reports API 6.13.0时出现错误。

huangapple go评论76阅读模式
英文:

Error when compiling Jasper Reports using Jasper Reports API 6.13.0 with Adopt OpenJDK 11

问题

以下是翻译好的内容:

我们有一个实用程序(CompileJasperReports.jar),用于编译在文件夹中找到的所有报表。

在使用 JasperReports 6.7 API 与 Java 8 时,此实用程序运行良好。调用为

"C:\Program Files\Java\jdk1.8.0_172\bin\java" -jar CompileJasperReports.jar <包含.jrxml文件的输入文件夹> <.jasper文件的输出文件夹>

以下是由 CompileJasperReports.jar 使用的 JAR 文件

  • jasperreports-6.7.0.jar
  • commons-beanutils-1.9.3.jar
  • commons-collections-3.2.2.jar
  • commons-digester-2.1.jar
  • commons-logging-1.2.jar

现在,我们尝试迁移到 JasperReports 6.13.0 API 和 Java 11。

该实用程序已使用 Java 11 编译,并调用如下:

"C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin\java" -jar --add-opens java.xml/com.sun.org.apache.xerces.internal.util=ALL-UNNAMED CompileJasperReports.jar <包含.jrxml文件的输入文件夹> <.jasper文件的输出文件夹>

以下是由 CompileJasperReports.jar 使用的 JAR 文件

  • jasperreports-6.13.0.jar
  • commons-beanutils-1.9.4.jar
  • commons-collections4-4.4.jar
  • commons-digester-2.1.jar
  • commons-logging-1.2.jar

大多数报表可以无问题编译,但某些报表会出现以下错误:

编译 master_report.jrxml 为 master_report.jasper...

java.lang.NullPointerException
at net.sf.jasperreports.engine.design.JRAbstractCompiler.deleteSourceFiles(JRAbstractCompiler.java:407)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:281)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:358)
at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:274)
at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:256)
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:555)
at com.ietsol.enterprise.CompileJasperReports.main(CompileJasperReports.java:24)

该实用程序的主要代码为

private static final String defExtension = ".jrxml";
private static final String compExtension = ".jasper";

public static void main(String[] args) {
    if (!checkArguments(args)) 
        return;
    
    File inputDir = new File(args[0]);
    File[] files = inputDir.listFiles((dir, name) -> name.endsWith(defExtension));
    for (File reportDef : files) {
        String defFileName = reportDef.getName();
        String compFileName = defFileName.replace(defExtension, compExtension);
        System.out.println("Compiling " + defFileName + " to " + compFileName + "...");
        try {
            JasperCompileManager.compileReportToFile(args[0] + File.separator + defFileName, args[1] + File.separator + compFileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }       
}

欢迎提供任何提示。

英文:

we have a utility (CompileJasperReports.jar) that we use to compile all reports found in a folder

When using JasperReports 6.7 API with Java 8 the utility runs fine. The call is

"C:\Program Files\Java\jdk1.8.0_172\bin\java" -jar CompileJasperReports.jar <in-folder containing .jrxml files> <out-folder for .jasper files>

These are the jars that are used by the CompileJasperReports.jar

  • jasperreports-6.7.0.jar
  • commons-beanutils-1.9.3.jar
  • commons-collections-3.2.2.jar
  • commons-digester-2.1.jar
  • commons-logging-1.2.jar

Now we are trying to migrate to JasperReports 6.13.0 API and Java 11.

The utility is compiled with Java 11 and the call to it is

"C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin\java" -jar --add-opens java.xml/com.sun.org.apache.xerces.internal.util=ALL-UNNAMED CompileJasperReports.jar <in-folder containing .jrxml files> <out-folder for .jasper files>

These are the jars that are used by the CompileJasperReports.jar

  • jasperreports-6.13.0.jar
  • commons-beanutils-1.9.4.jar
  • commons-collections4-4.4.jar
  • commons-digester-2.1.jar
  • commons-logging-1.2.jar

Most of the reports are compiled without problems, but for some the following error occurs:

Compiling master_report.jrxml to master_report.jasper...

java.lang.NullPointerException
at net.sf.jasperreports.engine.design.JRAbstractCompiler.deleteSourceFiles(JRAbstractCompiler.java:407)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:281)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:358)
at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:274)
at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:256)
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:555)
at com.ietsol.enterprise.CompileJasperReports.main(CompileJasperReports.java:24)

The main code of the utility is

private static final String defExtension = &quot;.jrxml&quot;;
private static final String compExtension = &quot;.jasper&quot;;

public static void main(String[] args) {
    if (!checkArguments(args)) 
        return;
    
    File inputDir = new File(args[0]);
    File[] files = inputDir.listFiles((dir, name) -&gt; name.endsWith(defExtension));
    for (File reportDef : files) {
        String defFileName = reportDef.getName();
        String compFileName = defFileName.replace(defExtension, compExtension);
        System.out.println(&quot;Compiling &quot; + defFileName + &quot; to &quot; + compFileName + &quot;...&quot;);
        try {
            JasperCompileManager.compileReportToFile(args[0] + File.separator + defFileName, args[1] + File.separator + compFileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }       
}

Any hints are highly welcome.

答案1

得分: 2

这是JasperReports 6.13.0中的一个错误。

一个解决该错误的方法是在您的应用程序中包含一个JDT/ECJ编译器jar文件。JasperReports 6.13.0列出了ECJ 3.21.0作为依赖项,您可以在此处获取它。

另一种替代方法是在jasperreports.properties中添加以下属性,如果您的应用程序中有这个文件:

net.sf.jasperreports.legacy.compiler.source.included.parameters=REPORT_PARAMETERS_MAP

如果您没有或不想要jasperreports.properties文件,您也可以以编程方式设置该属性:

DefaultJasperReportsContext.getInstance().setProperty(
        ReportSourceCompilation.PROPERTY_LEGACY_SOURCE_INCLUDED_PARAMETERS, 
        JRParameter.REPORT_PARAMETERS_MAP);
英文:

It's a bug in JasperReports 6.13.0.

One way to workaround the bug is to include a JDT/ECJ compiler jar in your application. JasperReports 6.13.0 lists ECJ 3.21.0 as dependency, you can get it here.

An alternative workaround is to add the following property to jasperreports.properties, if you have one in your application:

net.sf.jasperreports.legacy.compiler.source.included.parameters=REPORT_PARAMETERS_MAP

You can also set the property programmatically if you don't have/want a jasperreports.properties file:

	DefaultJasperReportsContext.getInstance().setProperty(
			ReportSourceCompilation.PROPERTY_LEGACY_SOURCE_INCLUDED_PARAMETERS, 
			JRParameter.REPORT_PARAMETERS_MAP);

huangapple
  • 本文由 发表于 2020年7月24日 15:55:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63069258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定