gordonb Posted March 19, 2009 Share Posted March 19, 2009 In my application, I want to use JasperFillManager.fillReport to fill a pre-compiled .jasper report and save the result as a PDF file, which the user can view and/or download. In an Apple OS X environment this works fine. In a Windows XP or Windows 2003 server environment the same code does not fill the report AND does not throw an error. Can anyone help?Here is the code I am using, where jasperIn is the name of the .jasper report file, conn is the appropriate database connection, and HashMap contains the parameters needed for the report. The instance variable pdf, a String, is used to display status and error messages in the main application.After this routine completes, the value of pdfMessage is:report file = E:JasperReportsPT2DemoBrandsByName.jasper exists; lines 1; 9; This message indicates that the call to fillReport failed and jumped directly to the finally block without throwing either a JRException or a plain vanilla Exception. public static Long savePdfReportAsFile(String jasperIn, String pdfOut, Connection conn, HashMap parameters) { pdfMessage = (new File(jasperIn).exists() ? "exists" : "does not exist"); Long ret = new Long(-99); try { pdfMessage = "report file = " + jasperIn + " " + pdfMessage + "; lines 1; "; // for debug JasperPrint jPrint = JasperFillManager.fillReport(jasperIn, parameters, conn); pdfMessage += "2; "; // for debug if (jPrint == null) { ret = new Long(-101); return (ret); } JasperExportManager.exportReportToPdfFile(jPrint, pdfOut); f = new File(pdfOut); if (!f.exists()) return (new Long(-102)); ret = f.length(); } catch (JRException e) { pdfMessage += "8a"; // for debug String s = e.getMessage(); System.out.println(s); ret -= 100; } catch (Exception e) { String s = e.getMessage(); System.out.println(s); ret -= 100; pdfMessage += "8b; "; // for debug } finally { pdfMessage += "9; "; // for debug return (ret); } } Link to comment Share on other sites More sharing options...
gordonb Posted March 19, 2009 Author Share Posted March 19, 2009 Some more information: developed in NetBeans 6.1 nd also Netbeans 6.5; running in Glassfish 2, under OS X.4 and Windows XP with latest SP Link to comment Share on other sites More sharing options...
lucianc Posted March 23, 2009 Share Posted March 23, 2009 Well, maybe the application throws a java.lang.Error and the return statement in finally (which sounds like a strange thing to do) loses the exception. Try to add an catch(Throwable) block, or get rid of the return in finally.HTH,Lucian Link to comment Share on other sites More sharing options...
gordonb Posted March 23, 2009 Author Share Posted March 23, 2009 Thank you, Lucian, for your suggestion. When I moved the return statement out of the finally block I did see an error message:Caused by: javax.faces.FacesException: #{ReportPage.btnReportPdf_action}: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log; I added the commons logging jars to the Netbeans dev. environment and referenced them in the project, but after that I am still getting the same error message. Any further suggestions? Thanks againBill Link to comment Share on other sites More sharing options...
lucianc Posted March 24, 2009 Share Posted March 24, 2009 If you're still getting the same exception, the commons logging jar is not on the application's classpath. I'm afraid I don't have any suggestion on this, I'm not proficient in Netbeans and I don't know why the jar is not placed on the classpath.Regards,Lucian Link to comment Share on other sites More sharing options...
gordonb Posted March 31, 2009 Author Share Posted March 31, 2009 Lucian,Your comments about classpaths and the need to ensure commons-logging was included were helpful.After making sure all those commons-*.jar files WERE in the class path I still got the error. Eventually a google search on the name of the class that was not defined (Lorg/apache/commons/logging/Log), which is not included in the commons-logging jar, led me to a helpful comment about the Sun Java Server. Although the reference was to version 8.2 this fix also worked with the durrent distribution of the Sun Glassfish server (v2.1 (9.1.1) (build b60e-fcs))*********** (borrowed from http://www.dreamincode.net/forums/showtopic76527.htm)The problem was with Sun App Server 8.2 as it ships with its own copy of the digester API. Unfortunately it ships with the older version that does not have the "setSubstitutor" method. In order to resolve this issue one needs to add the following definition in the sun-web.xml file.<class-loader delegate="false" />This will use the API version that is bundled with your applcaition.***********after making this change in the configuration file, the PDF reports work correctly. This might be a useful FAQ Thanks again for your help, and for such a nice product.Bill Gordon 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