Problem when calling BIRT file in java as standalone

viky4frnds
edited February 11, 2022 in Analytics #1
<p>Hi,</p>
<p>  I am new to this BIRT Report.I created BIRT Report(firstReport..rptdesign)<br>
using Eclipse.I needed to call this report file from java as standalone.So i created below java code and run(Runas -> Java application).When i run this java class i m getting error " org.osgi.framework.BundleException: Exception in org.eclipse.osgi.framework.internal.core.SystemBundleActivator.start() of bundle org.eclipse.osgi.".Is there any configuration issue?i have added all jars required for BIRT into my classpath.So any one can help me out this issue?</p>
<p><u><strong>JAVA Code</strong></u></p>
<p> </p>
<p>package TestBirt;<br>
import java.util.HashMap;<br>
import java.util.Map;<br>
import org.eclipse.birt.core.framework.Platform;<br>
import org.eclipse.birt.report.engine.api.EngineConfig;<br>
import org.eclipse.birt.report.engine.api.EngineException;<br>
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;<br>
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;<br>
import org.eclipse.birt.report.engine.api.HTMLRenderContext;<br>
import org.eclipse.birt.report.engine.api.HTMLRenderOption;<br>
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;<br>
import org.eclipse.birt.report.engine.api.IReportEngine;<br>
import org.eclipse.birt.report.engine.api.IReportEngineFactory;<br>
import org.eclipse.birt.report.engine.api.IReportRunnable;<br>
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;<br>
import org.eclipse.birt.report.engine.api.ReportEngine;<br>
public class TestBirtAPI {</p>
<p> static void executeReport() throws EngineException<br>
 {<br>
  <br>
  Map parameters = new HashMap();  <br>
        parameters.put("PARAM1", "1234");       <br>
        EngineConfig config = null;<br>
        try<br>
        {<br>
         String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;<br>
         config = new EngineConfig();                   <br>
                config.setEngineHome("C:\\birt-runtime-4_2_0\\birt-runtime-4_2_0\\ReportEngine");           <br>
            HTMLEmitterConfig hc = new HTMLEmitterConfig( );<br>
            HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );<br>
            hc.setImageHandler( imageHandler );<br>
            config.setEmitterConfiguration( HTMLRenderOption.OUTPUT_FORMAT_HTML, hc );<br>
            Platform.startup(config);<br>
            ReportEngine engine = new ReportEngine( config );<br>
            IReportRunnable report = null;<br>
            String reportFilepath = "D:/BIRT_WS/test_Birt/firstReport.rptdesign";<br>
            try{<br>
             report = engine.openReportDesign(reportFilepath);<br>
            }<br>
            catch(Exception e)<br>
            {<br>
             System.err.println( "Report " + reportFilepath + " not found!\n" );<br>
                engine.destroy( );<br>
                return;<br>
            }<br>
            IRunAndRenderTask task = engine.createRunAndRenderTask( report );<br>
            HTMLRenderOption options = new HTMLRenderOption( );<br>
            options.setOutputFormat(format);<br>
            options.setOutputFileName( "D:/BIRT_WS/test_Birt/REPORT.pdf" );<br>
            task.setRenderOption( options );<br>
            task.setParameterValues(parameters);<br>
            try {<br>
                task.run( );<br>
            }<br>
            catch ( EngineException e1 ) {<br>
                System.err.println( "Report " + reportFilepath + " run failed.\n" );<br>
                System.err.println( e1.toString( ) );<br>
            }<br>
            engine.destroy( );<br>
            return;</p>
<p>        }<br>
        catch (Exception e)<br>
        {<br>
         e.printStackTrace();<br>
        }</p>
<p> }<br>
 <br>
 /**<br>
  * @param args<br>
  */<br>
 public static void main(String[] args) {<br>
  // TODO Auto-generated method stub</p>
<p>    try<br>
    {<br>
     executeReport();<br>
    }<br>
    catch(Exception e)<br>
    {<br>
     e.printStackTrace();<br>
    }<br>
 }</p>
<p>}</p>

Comments

  • <p>You're using code from very old versions. Try this:</p>
    <p> </p>
    <p></p><pre class="_prettyXprint _linenums:0">package TestBirt;
    import java.util.HashMap;
    import java.util.Map;
     
    import org.eclipse.birt.core.framework.Platform;
    import org.eclipse.birt.report.engine.api.EngineConfig;
    import org.eclipse.birt.report.engine.api.EngineException;
    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.PDFRenderOption;
    public class TestBirtAPI {
     static void executeReport() throws EngineException
     {
      
    Map<String, String> parameters = new HashMap<String, String>();  
            parameters.put("PARAM1", "1234");       
            EngineConfig config = null;
            IReportEngine engine = null;
            try
            {
             config = new EngineConfig();                   
             config.setLogConfig("/logs", java.util.logging.Level.WARNING);
             Platform.startup(config);
             IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
             engine = factory.createReportEngine( config );
             IReportRunnable report = null;
             String reportFilepath = "D:/BIRT_WS/test_Birt/firstReport.rptdesign";
             try{
                 report = engine.openReportDesign(reportFilepath);
             }
             catch(Exception e)
             {
                 System.err.println( "Report " + reportFilepath + " not found!\n" );
                 engine.destroy( );
                    return;
             }
             IRunAndRenderTask task = engine.createRunAndRenderTask( report );
             PDFRenderOption options = new PDFRenderOption( );
             options.setOutputFormat("pdf");
             options.setOutputFileName( "D:/BIRT_WS/test_Birt/REPORT.pdf" );
             task.setRenderOption( options );
             task.setParameterValues(parameters);
             try {
                 task.run( );
             }
             catch ( EngineException e1 ) {
                 System.err.println( "Report " + reportFilepath + " run failed.\n" );
                 System.err.println( e1.toString( ) );
             }
               engine.destroy( );
               return;
            }
          catch (Exception e)
          {
             e.printStackTrace();
          }
     }
     
     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
        try
        {
         executeReport();
        }
        catch(Exception e)
        {
         e.printStackTrace();
        }
     }
    }
    </pre>
    Warning No formatter is installed for the format ipb
  • <p>Hello</p>
    <p>i used your code to creating a report using eclipse(mars) birt designer</p>
    <p>but i have a error:</p>
    <p>===================================================================================================</p>
    <div>Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.birt.report.engine.api.EngineConfig.getLogRollingSize()I</div>
    <div>at org.eclipse.birt.report.engine.api.impl.ReportEngine.intializeLogger(ReportEngine.java:222)</div>
    <div>at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:136)</div>
    <div>at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:18)</div>
    <div>at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:1)</div>
    <div>at java.security.AccessController.doPrivileged(Native Method)</div>
    <div>at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:14)</div>
    <div>at org.eclipse.birt.report.engine.api.ReportEngine.<init>(ReportEngine.java:71)</div>
    <div>at test.main(test.java:30)</div>
    <div>===================================================================================================</div>
    <div>my java(jdk) is 1.8</div>
    <div>i can not find the problem, can you help me please?</div>
  • <p>How to Provide the Relative Path of design to Report Engine.</p>
    <p> </p>
    <p>>><span style="color:rgb(102,0,102);">String</span><span> reportFilepath </span><span style="color:rgb(102,102,0);">=</span><span> </span><span style="color:rgb(0,136,0);">"D:/BIRT_WS/test_Birt/firstReport.rptdesign"</span><span style="color:rgb(102,102,0);">;</span></p>
    <p> </p>
    <p><span style="color:rgb(102,102,0);">>></span><span style="color:rgb(102,0,102);">String</span><span> reportFilepath </span><span style="color:rgb(102,102,0);">=</span><span> </span><span style="color:rgb(0,136,0);">"./Webapp/firstReport.rptdesign"</span><span style="color:rgb(102,102,0);">;</span></p>
    <p>?</p>