问题
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 = ".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();
}
}
}
Any hints are highly welcome.
回答1:
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);
来源:https://stackoverflow.com/questions/63069258/error-when-compiling-jasper-reports-using-jasper-reports-api-6-13-0-with-adopt-o