nirvanb Posted April 2, 2010 Share Posted April 2, 2010 I am trying to create a .jasper file from an jrxml file using JasperCompileManager.compileReportToFile("jrxml file"). I am getting File Not Found Exception. I am not sure of the algorithm that the JasperCompileManager.compileReportToFile() is using to search the file to compile. I am able to locate the file in the java code using getResourceAsStream("/com/jrxml/FirstReport.xml"). Why is JasperCompileManager.compileReportToFile() unable to locate the file when the getResourceAsStream("/com/jrxml/FirstReport.xml") finds it successfully. My application is based on swing.regardsnirvan. Link to comment Share on other sites More sharing options...
minhduc Posted April 2, 2010 Share Posted April 2, 2010 rename your report template file to [template].jrxml and check it out again :)) Link to comment Share on other sites More sharing options...
nirvanb Posted April 2, 2010 Author Share Posted April 2, 2010 Thanks for the reply, but unfortunately changing extension to jrxml still gives me the same File Not Found Exception.regards,nirvan. Link to comment Share on other sites More sharing options...
minhduc Posted April 2, 2010 Share Posted April 2, 2010 Is a web application? When you deployed it on server, the File location and resource location are not same.If not, make sure com/jrxml/FirstReport.xml is located on your project folder, NOT in src folder.Anyway, I think you shoud use compileReport method and InputStream object. InputStream input = this.getClass().getResourceAsStream([your resource jrxml template ]); JasperDesign design = JRXmlLoader.load(input); JasperReport report = JasperCompileManager.compileReport(design); System.out.println("Template id loaded and complied"); JasperPrint print = JasperFillManager.fillReport(report, parameters, jRBeanArrayDataSource); System.out.println("Filled data"); JRExporter exporter = null; exporter = new JRXlsExporter();Post Edited by minhduc at 04/02/2010 08:36 Link to comment Share on other sites More sharing options...
nirvanb Posted April 2, 2010 Author Share Posted April 2, 2010 minhducWrote: Is a web application? When you deployed it on server, the File location and resource location are not same. If not, make sure com/jrxml/FirstReport.xml is located on your project folder, NOT in src folder. Anyway, I think you shoud use compileReport method and InputStream object. InputStream input = this.getClass().getResourceAsStream([your resource jrxml template ]); JasperDesign design = JRXmlLoader.load(input); JasperReport report = JasperCompileManager.compileReport(design); System.out.println("Template id loaded and complied"); JasperPrint print = JasperFillManager.fillReport(report, parameters, jRBeanArrayDataSource); System.out.println("Filled data"); JRExporter exporter = null; exporter = new JRXlsExporter(); Post Edited by minhduc at 04/02/2010 08:36 As mentioned in the question, I am developing a swing based application, not web based.I can use compileReport() as I can get a reference to InputStream. But looking ahead, I will require to store the .jasper compiled file so as to avoid re-compiling it again every time it is needed.regards,nirvan. Link to comment Share on other sites More sharing options...
minhduc Posted April 2, 2010 Share Posted April 2, 2010 write input to file to get jasper filepublic void writeToFile(InputStream is, File file) { try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); int c; while((c = is.read()) != -1) { out.writeByte©; } is.close(); out.close(); } catch(IOException e) { System.err.println("Error Writing/Reading Streams."); } }[/code]writeToFile(input, new File([jasper file]); Link to comment Share on other sites More sharing options...
minhduc Posted April 2, 2010 Share Posted April 2, 2010 sorry, I go wrong,should use JasperCompileManager.compileReportToFile(design, destFileName); Link to comment Share on other sites More sharing options...
nirvanb Posted April 2, 2010 Author Share Posted April 2, 2010 There is no search algorithm used by compileReportToFile(String sourceFileName). Looking at the source code the compileReportToFile(String sourceFileName) calls JRXmlLoader.load(sourceFileName) which calls JRXmlLoader.load(new File(sourceFileName)) which creates InputFileStream based on the file passed to it. In short, it means that the file name passed as sourceFileName should be absolute system file name including path or be in the current directory from where the class is executed.I think that the other solutions discussed previously in the post has to be thought of and we could not directly rely on compileReportToFile(String sourceFileName) to find the jrxml file for us. I am very new to JasperReports and so I am not entirely confident making the above assumptions.regards,Nirvan. 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