Problem when calling BIRT file in java as standalone

Hi,


  I am new to this BIRT Report.I created BIRT Report(firstReport..rptdesign)

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?


JAVA Code


 


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.HTMLCompleteImageHandler;

import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;

import org.eclipse.birt.report.engine.api.HTMLRenderContext;

import org.eclipse.birt.report.engine.api.HTMLRenderOption;

import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;

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 TestBirtAPI {


 static void executeReport() throws EngineException

 {

  

  Map parameters = new HashMap();  

        parameters.put("PARAM1", "1234");       

        EngineConfig config = null;

        try

        {

         String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;

         config = new EngineConfig();                   

                config.setEngineHome("C:\\birt-runtime-4_2_0\\birt-runtime-4_2_0\\ReportEngine");           

            HTMLEmitterConfig hc = new HTMLEmitterConfig( );

            HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );

            hc.setImageHandler( imageHandler );

            config.setEmitterConfiguration( HTMLRenderOption.OUTPUT_FORMAT_HTML, hc );

            Platform.startup(config);

            ReportEngine engine = new ReportEngine( 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 );

            HTMLRenderOption options = new HTMLRenderOption( );

            options.setOutputFormat(format);

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

    }

 }


}


Comments

  • You're using code from very old versions. Try this:


     


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

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog

    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • Hello


    i used your code to creating a report using eclipse(mars) birt designer


    but i have a error:


    ===================================================================================================


    Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.birt.report.engine.api.EngineConfig.getLogRollingSize()I

    at org.eclipse.birt.report.engine.api.impl.ReportEngine.intializeLogger(ReportEngine.java:222)

    at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:136)

    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 org.eclipse.birt.report.engine.api.ReportEngine.<init>(ReportEngine.java:71)

    at test.main(test.java:30)

    ===================================================================================================

    my java(jdk) is 1.8

    i can not find the problem, can you help me please?
  • How to Provide the Relative Path of design to Report Engine.


     


    >>String reportFilepath = "D:/BIRT_WS/test_Birt/firstReport.rptdesign";


     


    >>String reportFilepath = "./Webapp/firstReport.rptdesign";


    ?


Sign In or Register to comment.