JasperReports Library和MongoDB [英] JasperReports Library and MongoDB

查看:89
本文介绍了JasperReports Library和MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的源代码:

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正在运行。
我在名为test的文件夹中有gocoffee.jrxml,当我编译时,我得到BUILD SUCCESSFUL但是我的test文件夹中没有pdf文件。

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);

此行之后:

JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

它不起作用。

(我刚修好此错误在此之前。也许是相关的)

(I just fixed this error before this one. Maybe its related)

谢谢!

Ps:mdahlman你很棒

Ps: mdahlman you are awesome

推荐答案

在iReport中工作但在使用JasperReports的应用程序中失败的报告可能意味着你'缺少查询执行器。创建jasperreports.properties(或编辑现有的),确保它在类路径上,并添加以下行:

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:

net.sf.jasperreports.query.executer.factory.MongoDbQuery=com.jaspersoft.mongodb.MongoDbQueryExecuterFactory

注1:您应该查看发布到 jasperforge 的源代码中的工作单元测试(使用此构思)。那真的应该有你所需要的一切。

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.

注意2:我们最近发现必须这样做很麻烦,所以我们更新了连接器以获得副本执行相同角色的jasperreports_extension.properties。但是它包含在连接器.jar文件中,因此您不必担心它。这将很快发布。

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.

这篇关于JasperReports Library和MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆