Reputation: 9526
I'm using JasperReport
to generate a PDF
. Now I'm using the compiled .jasper
, file but I want a backup
in case of error to let Jasper
recompile the original JRXML
file.
How can I do this? Is this a best practice?
This is my code:
InputStream reportC1 = ReportService.class.getResourceAsStream(JASPER_IN_PACKAGE);
bytes = JasperRunManager.runReportToPdf(reportC1, params, new JRBeanCollectionDataSource(records));
PdfReader doc = new PdfReader(bytes);
Where JASPER_IN_PACKAGE
is a constant to .jasper
file.
Upvotes: 0
Views: 4277
Reputation: 6476
You can easily compile .jrxml files with
JasperCompileManager.compileReportToFile(sourceFile, targetFile);
where sourceFile
is a File
to your .jrxml, targetFile
is the File
to your to-be-created .jasper file.
And for the "Best Practice": I always deploy only the .jrxml files and compile them if the respective .jasper file is older that the .jrxml file. This allows me to easily edit the source files without having to compile them locally. And it is IMHO also best practice because one should never commit anything which can be reconstructed, especially not binary content.
Upvotes: 2