So here is my source code :
import com.jaspersoft.mongodb.MongoDbConnection;
import com.jaspersoft.mongodb.MongoDbDataSource;
import java.io.File;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
public class Generate {
public static void main(String[] args) throws UnknownHostException {
try {
// - Connexion à la base
String mongoURI = "mongodb://localhost/test";
MongoDbConnection connection = null;
Map<String, Object> parameters = new HashMap<String, Object>();
try {
connection = new MongoDbConnection(mongoURI,null,null);
parameters.put(MongoDbDataSource.CONNECTION, connection);
JasperDesign jasperDesign = JRXmlLoader.load("/home/test/gocoffee.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
File jasperFile;
jasperFile = new File("/home/test/MongoDbReport.jasper");
JasperCompileManager.compileReportToFile("/home/test/gocoffee.jrxml", "/home/test/MongoDbReport.jasper");
JasperFillManager.fillReportToFile("/home/test/MongoDbReport.jasper", parameters);
JasperExportManager.exportReportToPdfFile("/home/test/MongoDbReport.jrprint");
} catch(Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Mongo is running.
I have gocoffee.jrxml in my folder named “test” and when I compile I get BUILD SUCCESSFUL but no pdf file appears in my “test” folder.
Interesting fact : if i do a
System.out.print("123");
after this line :
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
It doesn’t work.
(I just fixed this error before this one. Maybe its related)
Thanks !
Ps: mdahlman you are awesome
A report working in iReport but failing in your application that uses JasperReports probably means that you’re missing the query executer. Create jasperreports.properties (or edit your existing one), make sure it’s on the classpath, and add this line:
Note1: You should look at the working unit test (which uses this idea) in the source that’s posted to jasperforge. That really ought to have all that you need.
Note2: We recently figured out that it’s a hassle to have to do this, so we updated the connector to have a copy of jasperreports_extension.properties which performs the same role. But then it’s included in the connector .jar file, so you don’t have to worry about it. That will be posted soon.