2

Java プログラムで BIRT API を使用しています。私のコードは次のとおりです。

package com.tecnotree.mdx.product.utils;

import java.util.HashMap;
import java.util.logging.Level;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;


public class ExampleReport {

 public static void main(String[] args) {
  // Variables used to control BIRT Engine instance

  ReportEngine eng = null;
  IReportRunnable design = null;
  IRunAndRenderTask task = null;
  HTMLRenderOption renderContext = null;
  HashMap contextMap = null;
  HTMLRenderOption options = null;
  final EngineConfig conf = new EngineConfig();
  conf
    .setEngineHome("C:\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\ReportEngine");
  System.out.println("conf " + conf.getBIRTHome());

  conf.setLogConfig(null, Level.FINE);
  try {
   Platform.startup(conf);
  } catch (BirtException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }


  IReportEngineFactory factory = (IReportEngineFactory) Platform
    .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
  System.out.println("Factory : " + factory.toString());
  System.out.println(conf.toString());
  IReportEngine engine = factory.createReportEngine(conf);
  System.out.println("Engine : " + engine);

  try {
   design = eng
     .openReportDesign("C:\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\ReportEngine\\samples\\hello_world.rptdesign");
  } catch (Exception e) {
   System.err
     .println("An error occured during the opening of the report file!");
   e.printStackTrace();
   System.exit(-1);
  }
  task = eng.createRunAndRenderTask(design);
  renderContext = new HTMLRenderOption();
  renderContext.setImageDirectory("image");
  contextMap = new HashMap();
  contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
    renderContext);
  task.setAppContext(contextMap);

  options = new HTMLRenderOption();
  options.setOutputFileName("c:/temp/output.html");
  options.setOutputFormat("html");
  task.setRenderOption(options);
  try {
   task.run();
  } catch (Exception e) {
   System.err.println("An error occured while running the report!");
   e.printStackTrace();
   System.exit(-1);
  }
  System.out.println("All went well. Closing program!");
  eng.destroy();

 }
}

しかし、レポートの作成中に NullPointerException に直面しています。

STACKTRACE :
Exception in thread "main" java.lang.NullPointerException
 at org.eclipse.birt.report.engine.api.impl.ReportEngine$EngineExtensionManager.<init>(ReportEngine.java:784)
 at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:109)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:18)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:1)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:14)
 at com.tecnotree.mdx.product.utils.ExampleReport.main(ExampleReport.java:47)

これに関して私を助けてください...私のプロジェクトの締め切りに達しました...

返信ありがとうございます

前もって感謝します

4

4 に答える 4

3

私は同様の問題に直面し、Report Engine API ドキュメント ページを読んで解決しました。

基本的なことは次のとおりです。

  • プロジェクトのReportEngine フォルダーに配置します。これは、birt-runtime ダウンロード内にあります。.rptdesign ファイルを処理し、レポートを出力として取得するために必要なすべてのエンジンです。
  • ReportEngine/lib 内のすべての jar を Java ビルド パスに追加します。
  • ReportEngine/plugins/org.eclipse.birt.report.data.oda.jdbc_xxx で、DB に接続するために必要なドライバーを含む jar を追加します (Java ビルド パスに追加する必要はありません)。

HTML レポートを生成するサンプル コードは次のとおりです。

import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.*;

/**This class reads an .rptdesign file, 
 * and gives as output a report in HTML format 
 */
public class BirtEngineDesktop {

    public static void main(String[] args) {
        // Variables used to control BIRT Engine instance
        String reportName = "first_report.rptdesign";
        IReportEngine engine = null;
        IReportRunnable design = null;
        IRunAndRenderTask task = null;
        HTMLRenderOption renderContext = null;
        HashMap contextMap = null;
        HTMLRenderOption options = null;
        final EngineConfig conf = new EngineConfig();
        conf.setEngineHome("ReportEngine");
        System.out.println("BIRT_HOME: " + conf.getBIRTHome());
        conf.setLogConfig(null, Level.FINE);

        try {
            Platform.startup(conf);
        } catch (BirtException e1) {
            e1.printStackTrace();
        }

        IReportEngineFactory factory = (IReportEngineFactory) Platform
                .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
        System.out.println("Factory: " + factory.toString());
        System.out.println(conf.toString());
        engine = factory.createReportEngine(conf);
        System.out.println("Engine: " + engine);

        try {
            design = engine.openReportDesign("report/" + reportName); //report is needed in this folder
        } catch (Exception e) {
            System.err.println("An error occured during the opening of the report file!");
            e.printStackTrace();
            System.exit(-1);
        }
        task = engine.createRunAndRenderTask(design);
        renderContext = new HTMLRenderOption();
        renderContext.setImageDirectory("images");
        contextMap = new HashMap();
        contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
                renderContext);
        task.setAppContext(contextMap);

        //Set parameter values and validate, if the report requires it
        //task.setParameterValue("Years", 2.0);
        //task.validateParameters();

        options = new HTMLRenderOption();
        options.setOutputFileName("output/" + reportName + ".html"); //output HTML will go to this folder
        options.setOutputFormat("html");
        task.setRenderOption(options);
        try {
            task.run();
        } catch (Exception e) {
            System.err.println("An error occured while running the report!");
            e.printStackTrace();
            System.exit(-1);
        }
        System.out.println("All went well. Closing program!");
        engine.destroy();
        System.exit(0);
    }
}
于 2011-05-16T12:08:27.523 に答える
1

これが役立つかどうかはわかりませんが、問題のある行は次のとおりです。

IReportEngine engine = factory.createReportEngine(conf);

BIRT 用に独自の Web アプリケーションをコーディングすることはもうありません (会社の別の部門から提供された Web アプリケーションを使用しています)。それらのいずれかが修正されているかどうかは、自分で確認する必要があります。すべての注意、責任はありません:-)

違いは次のとおりです。

ログ構成エンジンをホームに設定した後、プラットフォームを開始する前に、HTML エミッターとプラットフォーム コンテキストも設定します。

HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig();
emitterConfig.setActionHandler (new HTMLActionHandler());
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
emitterConfig.setImageHandler (imageHandler);
conf.getEmitterConfigs().put ("html", emitterConfig);

IPlatformContext context = new PlatformServletContext( svrContext );
conf.setPlatformContext( context );

スタンドアロン アプリケーションの一部としてではなく、サーブレットで実行していたことに注意してください。したがって、おそらく必要になるでしょう:

IPlatformContext context = new PlatformFileContext( svrContext );

プラットフォーム コンテキスト用。それを試してみて、それが機能するかどうかを確認してください。PlatformFileContext がデフォルトであるため、どういうわけか私はそれを疑っています。ただし、エミッターは考慮すべきものかもしれません。

私が提案できる他の唯一の可能性は、実際にBIRT (特定のビルド) のソース コードを取得し、スタック トレースで問題のある行を確認することです。うまくいけば、どのパラメータが問題を引き起こしているのかを突き止めることができるはずです。

たとえば、最後の行ReportEngine.java:784は次の一部です。

void cacheOpenedDocument( ReportDocumentReader document ) {
    synchronized ( openedDocuments ) {
        LinkedEntry<ReportDocumentReader> entry
            = openedDocuments.add( document );
        document.setEngineCacheEntry( entry ); // << line 784
    }
}

documentしたがって、渡された が null であることはほぼ確実です。何が起こっているのかを調べるには、さまざまなレイヤーをたどる必要があります。

これが難しい場合は、バグ レポートを作成して専門家に任せた方がよい場合があります。または、Jason Weathersby の電子メール アドレスを手に入れることができる場合は、Jason Weathersby に直接迷惑をかけます :-)


余談ですが\、パスに恐ろしいエスケープ文字は必要ありません。Java は、(たとえば) を扱うのにまったく問題ありません。

conf.setEngineHome("C:/birt-runtime-2_5_2/ReportEngine");
于 2010-04-29T09:43:52.943 に答える
0

この質問はかなり古いことは知っていますが、今日この問題に遭遇し、原因を突き止めるのに長い時間がかかりました. 原因は、クラスパスにいくつかの birt / eclipse 依存関係を含めていたことです。何らかの理由で、これによりこの奇妙なエラーが発生します。私はmavenを使用しており、いくつかのカスタムエミッターが含まれています。私の解決策は、Eclipse の依存関係をカスタム エミッター pom で「提供済み」としてマークすることでした。これにより、すべての eclipse cruft がクラスパスに入るのを防ぎ、代わりに BIRT の OSGI ロードに依存してすべてを処理しました。

于 2011-05-31T20:47:31.290 に答える