Hi Friends, Here is my java program which uses jasper reports4.5 and I’m using netbeans ide6.8 jrxml file gets compiled successfully but it shows some error in the line of code where i try to export it to pdf or anything else here is my code import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.HashMap; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.export.JRXlsExporter; public class XMLDataSourceSample{ public static Connection establishConnection() throws ClassNotFoundException { Connection connection = null; try { Class.forName(““COM.ibm.db2.jdbc.app.DB2Driver””); String URL = ““jdbc:db2://localhost:50000/tnpltest””; connection = DriverManager.getConnection(URL,““Ramp””,““naandhan””); connection.setAutoCommit(false); } catch(SQLException exception) { exception.printStackTrace(); } return connection; } public static void main(String
ar) throws ClassNotFoundException, JRException { /* JasperReport is the object 2. that holds our compiled jrxml file
/ JasperReport jasperReport; /
JasperPrint is the object contains 7. report after result filling process */ JasperPrint jasperPrint; Connection connection = establishConnection(); HashMap jasperParameter = new HashMap(); jasperParameter.put(““TITLE””, ““Something””); jasperParameter.put(““GROUP””, ““Something””); jasperParameter.put(““SUBGROUP””, ““Something””); jasperParameter.put(““SOURCE””, ““Something””); jasperReport = JasperCompileManager.compileReport(““C:/users/ramp/report1.jrxml””); jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection); JasperExportManager.exportReportToPdfFile(jasperPrint, ““C:/sample_report.pdf””);
//JasperExportManager.exportReportToPdfFile
(““C:/users/ramp/report1.jrxml””);
//JasperExportManager.exportReportToHtmlFile
(jasperPrint, ““C:/sample_report.html”” ); //JRXlsExporter exporter = new JRXlsExporter();
//exporter.setParameter
(JRExporterParameter.JASPER_PRINT, jasperPrint);
//exporter.setParameter
(JRExporterParameter.OUTPUT_FILE_NAME, ““C:/simple_report.xls”” );
//exporter.exportReport
(); } } And the exception is run: Exception in thread ““main”” java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:117) at XMLDataSourceSample.main(XMLDataSourceSample.java:70) Caused by: java.lang.ClassNotFoundException: com.lowagie.text.DocumentException at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) … 2 more Java Result: 1 BUILD SUCCESSFUL (total time: 36 seconds) Please do reply me the reason and solution Thanx in advance… Ramprakash. P
You can use the following link to get the appropriate jar file:
http://www.jarfinder.com/index.php/java/info/com.lowagie.text.DocumentException
Thanks
Om Yadav