nkamir Posted April 2, 2009 Share Posted April 2, 2009 Hi,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? Code: Also, How do I use this absolute path with a reletive path? Appreciated.... Post Edited by Nasir Amir at 04/02/09 18:38 Link to comment Share on other sites More sharing options...
lucianc Posted April 3, 2009 Share Posted April 3, 2009 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).HTH,LucianCode:JasperReport jasReport = (JasperReport) JRLoader.loadObject(compiledReportFile); Link to comment Share on other sites More sharing options...
nkamir Posted April 3, 2009 Author Share Posted April 3, 2009 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:D:/Working/MyApp/src/MyApp/MyReportsJrxml/AccountActivityReport.jasperthe absolute path of the java class is:D:/Working/MyApp/src/MyApp/MyReports/AccountActivityReport.classI'm trying to access it as ../MyReportsJrxml/AccountActivity.jasper"; what could be the issue? Link to comment Share on other sites More sharing options...
nopain_nogain Posted April 3, 2009 Share Posted April 3, 2009 What you want to export file type?Html?xls?pdf?This is my test code,export fill type is html,and it run successful. String reportFilePath = root_path + "WEB-INF/classes/com/sunshine/jasper/report.jasper";JasperReport report = (JasperReport) JRLoader.loadObject(reportFilePath); JasperPrint jasperPrint = JasperFillManager.fillReport(report,null, conn); JRHtmlExporter exporter = new JRHtmlExporter(); req.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image="); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK"); exporter.exportReport(); Hope help you. Link to comment Share on other sites More sharing options...
nkamir Posted April 3, 2009 Author Share Posted April 3, 2009 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:D:/MyApplication/src/App/MyReports/AccountActivityReport.classand the report file is:D:/MyApplication/src/App/MyReportsJrxml/AccountActivityReport.jasper I wanna call this report as:../MyReportsJrxml/AccountActivity.jasper" Appreciated... Post Edited by Nasir Amir at 04/06/09 13:13 Link to comment Share on other sites More sharing options...
lucianc Posted April 6, 2009 Share Posted April 6, 2009 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.Regards,Lucian Link to comment Share on other sites More sharing options...
arch_1 Posted February 26, 2013 Share Posted February 26, 2013 do you have an updated example of this that does not use deprecated APIs? Link to comment Share on other sites More sharing options...
arch_1 Posted February 26, 2013 Share Posted February 26, 2013 Actually found it Link to comment Share on other sites More sharing options...
arch_1 Posted February 26, 2013 Share Posted February 26, 2013 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); Link to comment Share on other sites More sharing options...
onlyappasaheb4 Posted August 19, 2016 Share Posted August 19, 2016 thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now