Right now I'm compiling and loading my jasper report from .jrxml file as following? How do I load my reports from a pre-compiled .jasper file?
JasperDesign jasDesign = JRXmlLoader.load("D:/Working/MyApp/src/MyoApp/MyReportsJrxml/AccountActivity.jrxml"); JasperReport jasReport = JasperCompileManager.compileReport(jasDesign); JasperPrint jasPrint = JasperFillManager.fillReport(jasReport, parameters, con); JasperViewer.viewReport(jasPrint,false);
Also, How do I use this absolute path with a reletive path?
Post Edited by Nasir Amir at 04/02/09 18:38
You should use JRLoader.loadObject to load compiled reports.
If you use relative paths they would be interpreted as relative to the current user directory, as per standard Java rules (see java.io.File).
Nice, the loadObject works just fine, Thanks.
Now, that document says:
"A relative pathname that does not specify a drive has no prefix."
but I get FileNotFoundException while trying it as following:
the absolute path of the jasper object is:
the absolute path of the java class is:
I'm trying to access it as
what could be the issue?
What you want to export file type?
This is my test code,export fill type is html,and it run successful.
String reportFilePath = root_path
JasperReport report = (JasperReport) JRLoader.loadObject(reportFilePath);
JasperPrint jasperPrint = JasperFillManager.fillReport(report,null, conn);
JRHtmlExporter exporter = new JRHtmlExporter();
Hope help you.
Actually, I'm able to generate my reports with absolute path, but I can't figure out how to use relative path to do the same thing.
The class that is calling the report file is:
and the report file is:
I wanna call this report as:
Post Edited by Nasir Amir at 04/06/09 13:13
Again, relative paths are relative to the JVM's current user directory, and not to the class that calls JasperReports methods.
If you want to specify paths as relative to your class, you'll have to call Class.getResource() yourselft and pass the result URL to JasperReports.
I use InputStreams to do the load that way I can have it in either class path or physical file or some other stream source.
InputStream jasperStream = getClass().getResourceAsStream("/Foo.jasper");
JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream);