尝试通过java程序加载Pentaho报告时抛出异常

时间:2015-03-05 21:19:24

标签: java report pentaho

此代码主要来自Pentaho的网站上的示例程序。目标是使用他们的API通过Pentaho报告生成HTML输出。 该报告是使用Pentaho 3.5.0-RC2

创建的

我使用的罐子版本如下: Pentaho的报告方法发动机的经典核心-3.5.0-RC2.jar libloader-1.1.1.jar libbase-1.1.1.jar

我得到的例外情况如下:

org.pentaho.reporting.libraries.resourceloader.ContentNotRecognizedException: None of the selected factories was able to handle the given data: ResourceKey{schema=org.pentaho.reporting.libraries.resourceloader.loader.URLResourceLoader, identifier=file:/C:/Users/elias.kopsiaftis/workspace_experimental/TestPentahoReport/bin/Test.prpt, factoryParameters={}, parent=null}
at org.pentaho.reporting.libraries.resourceloader.DefaultResourceManagerBackend.create(DefaultResourceManagerBackend.java:295)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.create(ResourceManager.java:387)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.create(ResourceManager.java:342)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.createDirectly(ResourceManager.java:205)
at ReportTester.getReportDefinition(ReportTester.java:74)
at ReportTester.getReport(ReportTester.java:25)
at ReportTester.main(ReportTester.java:84)
java.lang.NullPointerException
at ReportTester.getReport(ReportTester.java:26)
at ReportTester.main(ReportTester.java:84)

最后,代码片段!

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.io.*;

import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.base.util.StackableException;
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;

public class ReportTester {
    private String reportName = "FormCompleteUsagePerPartnerByMonth.prpt";
    private String reportPath = "";


    public void getReport() {
        try {
            final MasterReport report = getReportDefinition();
            report.getParameterValues().put("partner", "");
            report.getParameterValues().put("startingdate", "2015-03-01");
            report.getParameterValues().put("endingdate", "2015-03-05");
            HtmlReportUtil.createStreamHTML(report, System.out);
        } catch(Exception e) {
            e.printStackTrace();
        } 
    }



private MasterReport getReportDefinition() {
    try {
        // Using the classloader, get the URL to the reportDefinition file
        final ClassLoader classloader = this.getClass().getClassLoader();
        final URL reportDefinitionURL = classloader.getResource(reportPath + reportName);

        if(reportDefinitionURL == null) {
            System.out.println("URL was null");
        }
        // Parse the report file
        final ResourceManager resourceManager = new ResourceManager();
        resourceManager.registerDefaults();
        final Resource directly = resourceManager.createDirectly(reportDefinitionURL, MasterReport.class);
        return (MasterReport) directly.getResource();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

public static void main(String[] args) {
    ReportTester rt = new ReportTester();
    rt.getReport();
}




}

对此的任何建议都会非常感激,因为我一整天都在摸不着头脑。提前谢谢!

0 个答案:

没有答案