I am using the following code to print a report:
JasperPrint jasperPrint = null;
try {
JasperCompileManager.compileReportToFile("C:\\Nevro\\reports\\salesDetails.jrxml");
jasperPrint = JasperFillManager.fillReport("C:\\Nevro\\reports\\salesDetails.jasper", new HashMap(),
new JRTableModelDataSource(itemTable.getModel()));
JasperViewer jasperViewer = new JasperViewer(jasperPrint);
jasperViewer.setVisible(true);
} catch (JRException ex) {
Logger.getLogger(Invoice.class.getName()).log(Level.SEVERE, null, ex);
}
In the location C:\Nevro\reports\
I have created salesDetails.jrxml
. Then in Java code I read the file and compile it. I expected to create compiled file as salesDetails.jasper
but it create only null.jasper
.
Can any one give me a reason and solution to sort this out?
The filename is generated by this line of code within the Jasper library:
File destFile = new File(sourceFile.getParent(), jasperDesign.getName() + ".jasper");
It takes the path of the jrxml
file and generates the output file based on the name of your report (configured in the XML). In your case the report has no name, so you get null.jasper
.