Unable to find .jasper files in .jar
Chris M.Mar 19 2007 — edited Mar 19 2007I'm building a java application, and when i run the application in jdeveloper everything works just fine, but when i build the application and try to run the .jar file i run into this issue when trying to create my reports.
net.sf.jasperreports.engine.JRException: Could not load object from location : .
cecs.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLo
ader.java:266)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubre
port.java:303)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFi
llElementContainer.java:274)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
400)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVe
rticalFiller.java:1273)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVertic
alFiller.java:614)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRV
erticalFiller.java:209)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
alFiller.java:109)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
751)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
660)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63
)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
nager.java:402)
at CEC.view.DataHandler.createReport(DataHandler.java:810)
at CEC.view.Report.but_Save_actionPerformed(Report.java:345)
at CEC.view.Report$9.actionPerformed(Report.java:81)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here is the code to compile and print out the report.
public void createReport(String key, String path, File[] file, String query) throws Exception{
// Load all the reports
JasperReport[] report = new JasperReport[file.length];
JasperDesign[] design = new JasperDesign[file.length];
Map parameters = new HashMap();
design[0] = JRXmlLoader.load(getClass().getResource(file[0].toString()).openStream());
for (int i=1; i < file.length; i++){
//report[i] = (JasperReport) JRLoader.loadObject(getClass().getResource(file.toString()).getFile());
//design[i] = JRXmlLoader.load(getClass().getResource(file[i].toString()).openStream());
report[i] = JasperCompileManager.compileReport(getClass().getResource(file[i].toString()).openStream());
System.out.println(file[i].toString()+": Compiled OK");
}
// Set the custom query for the report if need be
if (!query.equalsIgnoreCase("")){
JRDesignQuery designQuery = new JRDesignQuery();
designQuery.setText(query);
design[0].setQuery(designQuery);
}
// Compile the report and export it to the path that the user selected
report[0] = JasperCompileManager.compileReport(design[0]);
System.out.println(file[0].toString()+": Compiled OK");
parameters.put(key, "PDF JasperReport");
JasperPrint print = JasperFillManager.fillReport(report[0], parameters, conn);
OutputStream output = new FileOutputStream(new File(path));
JasperExportManager.exportReportToPdfStream(print, output);
output.close();
}