Here is my GeneratePdf.java Import ...
public class GeneratePdf {
public static void main(String[] args) {
try {
JRDataSou
Using the JRBeanCollectionDataSource is not the right way to go about using the MongoDB connector. Take a look at this test that comes with the Jaspersoft MongoDB Connector source:
MongoDbDatasource/src/test/java/com/jaspersoft/mongodb/ReportTest.java
Both the binary connector and the source are on the project page.
To keep this answer self-contained, here's a code snippet showing how to fill a MongoDB report. It's a modified extract from the file I mention above.
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();
}
}
You need to add following line:
JRProperties.setProperty("net.sf.jasperreports.query.executer.factory.MongoDbQuery", "com.jaspersoft.mongodb.query.MongoDbQueryExecuterFactory");
Verify path in datasource jar file, e.g. js-mongodb-datasource-0.5.0