keanhoo168 Posted December 27, 2010 Share Posted December 27, 2010 I have develope a simple java program to test jasperreport. But i am getting this exception.Can someone help me please?Here is the exception message:JRLoader.java:60)JasperFillManager.java:243)jasperTestMain.java:35)java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactoryNative Method) Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactoryat net.sf.jasperreports.engine.util.JRLoader.<clinit>(at net.sf.jasperreports.engine.JasperFillManager.fillReport(at func.jasperTestMain.main(Caused by:at java.net.URLClassLoader$1.run(Unknown Source)at java.security.AccessController.doPrivileged(at java.net.URLClassLoader.findClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)... 3 moreCode:import net.sf.jasperreports.engine.*;import net.sf.jasperreports.engine.export.*;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.util.*; public class jasperTestMain { public static void main(String[] args) { Connection connection = null; String fileName = "C:\\report1.jasper"; String outFileName = "C:\\test.pdf"; HashMap hm = new HashMap(); //Get database connection. try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]] connection = DriverManager.getConnection("jdbc:sqlserver://191.120.40.101:1433;databaseName=dbo;userName=sa;password=solution"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { // Fill the report using an empty data source JasperPrint print = JasperFillManager.fillReport(fileName, hm, connection); // Create a PDF exporter JRExporter exporter = new JRPdfExporter(); // Configure the exporter (set output file name and print object) exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); // Export the PDF file exporter.exportReport(); } catch (JRException e) { e.printStackTrace(); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } } Link to comment Share on other sites More sharing options...
augarte Posted December 27, 2010 Share Posted December 27, 2010 Which jar files have you added to your project? This error is because it is nof finding the LogFactory class. I guess it is in apache-loging jar file: http://commons.apache.org/logging/Download and add it to you project, but it is not the only jar file you need to work with Jasper. Here you have the list of jar files I'm using for my actual project, you will need some of them (not all, for example DynamicJasper is not necessary to test your program): - commons-beanutils-1.7- commons-collections-2.1- commons-logging-api-1.0.2- dom4j-1.6.1- DynamicJasper-3.0.0- DynamicJasper-3.0.0-tests- iText-2.1.0- jasperreports-3.1.2- jaxen-1.1.1- jdtCompilerAdapter- xalanHope this helps. Regards,Aitor 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