So mongoDB is running on 27017 and my collection name is test.
try {
// - Connection to base
String mongoURI = "mongodb://localhost:27017/test";
MongoDbConnection connection = null;
Map<String, Object> parameters = new HashMap<String, Object>();
try {
line35 connection = new MongoDbConnection(mongoURI, null, null);
parameters.put(MongoDbDataSource.CONNECTION, connection);
JasperDesign jasperDesign = JRXmlLoader.load("/home/gocoffee.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
File jasperFile;
jasperFile = new File("/home/MongoDbReport.jasper");
JasperCompileManager.compileReportToFile("/home/gocoffee.jrxml", "MongoDbReport.jasper");
JasperFillManager.fillReportToFile("/home/MongoDbReport.jasper", parameters);
JasperExportManager.exportReportToPdfFile("/home/MongoDbReport.jrprint");
}
And I have this error, I don’t understand why :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.jaspersoft.mongodb.MongoDbConnection.<init>(MongoDbConnection.java:62)
at Generate.main(Generate.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
The MongoURI seems fine and i think i don’t have any login or password
I agree with @AdamC: you need log4j. But I would say that it’s not a matter of “installing” it; you just need to add a log4j.jar file to your project classpath. Your code looks fine.
EDIT: moving info from my comment into the answer.
In addition to adding log4j.jar to the classpath, you also need a file called log4j.properties to configure log4j. You can create your own, or you can grab the copy from the MongoDB connector source on jasperforge. Look for src/main/resources/log4j.properties.