I am using the following code to call a jasper report
String reportSource = "/report.jrxml";
InputStream is = getClass().getResourceAsStream(reportSource);
JasperReport jasperReport = (JasperReport) JasperCompileManager.compileReport(is);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
Code is working fine when i run it in netbeans ide. but when i build the application and create the jar and run it , i am not getting report popup.
Don't convert the results of
getClass().getResource("report.jrxml")
to aString
, instead, you want to usegetClass().getResourceAsStream("report.jrxml")
and pass this intoJasperCompileManager.compileReport(InputStream)
Having said all that, you should not be deploying or compiling your
.jrxml
files at runtime.As part of your build process, you should be compiling the
.jrxml
files into.japser
files and simply loading and filling them at runtime.This way you save yourself the hassle of wasting runtime compiling the report each time...
ps, you can also use...