I'm developing app in Rational and this method is working locally... Creates pdf and everything... But when I compile my app and create jar with .jasper files and try to run my app over .bat it's not woriking anymore... like .jasper file is not found...
My method:
public void writePdfFile(List<MyObject> data, Map<
String,Object> map, String FilePathAndNAme) throws IOException, JRException{
InputStream is = getClass().getResourceAsStream("reports/my_name.jasper"); //like in my jar
String fileType = ".pdf";
String outFileName = FilePathAndNAme+this.yearmm+ fileType;
JRDataSource dataSource = new JRBeanCollectionDataSource(data);
try{
JasperPrint jasperPrint = JasperFillManager.fillReport(is, map, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, outFileName);
}
catch (JRException jre){
jre.printStackTrace();
}
catch (Exception e){
e.printStackTrace();
}
}
Error:
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: file:\C:\myJar.jar!\reports\my_name.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:77)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:536)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfFile(JasperRunManager.java:351)
at si.triglav.batch.porocilaKnjigovodstvo.myClass.writePdfFile(myClass.java:142)
at si.triglav.batch.porocilaKnjigovodstvo.myClass.executeBatch(myClass.java:88)
at si.triglav.batch.BatchRoot.initialization(BatchRoot.java:93)
at si.triglav.batch.porocilaKnjigovodstvo.myClass.main(myClass.java:43)
Caused by: java.io.FileNotFoundException: file:\C:\myJar.jar!\reports\my_name.jasper
... 7 more