2

Does anyone have a example about how to make a java mongoDB connector to use with JasperReports? I have been trying make it work but without any sucess... All example on internet looks like old versions of JasperReports...

I tried this code

GeneratePDF with JasperReports Library and MongoDB

String mongoURI = "mongodb://bdsandbox6:27017/test";
MongoDbConnection connection = null;
Map<String, Object> parameters = new HashMap<String, Object>();
try {
 connection = new MongoDbConnection(mongoURI, null, null);
  parameters.put(MongoDbDataSource.CONNECTION, connection);
  File jasperFile;
  jasperFile = new File("MongoDbReport.jasper");
  JasperCompileManager.compileReportToFile("MongoDbReport.jrxml",      "MongoDbReport.jasper");
   JasperFillManager.fillReportToFile("MongoDbReport.jasper", parameters);
  JasperExportManager.exportReportToPdfFile("MongoDbReport.jrprint");
}
} catch (Exception e) {
  e.printStackTrace();
} finally {
  if (connection != null) {
connection.close();
  }
}

But I ways got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger at com.jaspersoft.mongodb.connection.MongoDbConnection.(MongoDbConnection.java:64) at serverTeste.Rest.main(Rest.java:22) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger 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) ... 2 more

I know it seens I need log4j.jar but i tried it and I faill again. I guess I am using the wrong jars files...

I also tried it:

GeneratePDF with JasperReport Library and MongoDB

Without Sucess

Community
  • 1
  • 1
Joao Louzada
  • 183
  • 1
  • 10
  • Are you using Maven? – Alex K Jul 23 '16 at 08:15
  • @AlexK No. I did not. But today I started using maven to follow it [link](http://mongodbgeek.blogspot.com.br/) but I get a problem with itext. "Failure to find com.lowagie:itext:jar:2.1.7.js2 (...)" In the link the authos says "If you get any compilation error use the itext-2.1.7.js4.pom in you folder " But I do not have any idea how to use a *.pom file at maven. PS: I am just trying to learn maven because it. I have never used maven before... – Joao Louzada Jul 27 '16 at 04:13
  • @Alex K , BTW I saw your comment here [Link](http://stackoverflow.com/questions/9327718/jasperfillmanager-fillreport-and-mongo). You provided a link to article that is broke. Do you have another link to this article? [link](http://jasperforge.org/plugins/mwiki/index.php/Bigdatareportingfornosqlandhadoop/MongoDB) – Joao Louzada Jul 27 '16 at 22:20

0 Answers0