Unable to run birt report from a Standalone java project [message #260880] |
Tue, 06 November 2007 14:10  |
Eclipse User |
|
|
|
Hi,
I was able to execute my report from eclipse. But when i tried to
execute it from a standalone java program(it is written in JBuilder), i
got the following error.
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.birt.report.engine.api.ReportEngine.openReportDe sign(ReportEngine.java:111)
at subsreqrequest.RRTest.main(RRTest.java:27)
Can't load the report engine
Here is my program
package subsreqrequest;
import org.eclipse.birt.report.engine.api.*;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.exception.*;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
public class RRTest {
public RRTest() {
}
public static void main(String[] args) {
RRTest rrtest = new RRTest();
try {
EngineConfig config = new EngineConfig();
config.setEngineHome("C:/birt-runtime-2_1_1/ReportEngine");
System.out.println("EngineHome: " + config.getBIRTHome());
IReportEngine engine = new ReportEngine(config);
IReportRunnable design = engine.openReportDesign(
"C:/sampreport/Subs.rptdesign");
design.getReportName();
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2007, 10, 10);
task.setParameterValue("BeginDate", cal.getTime());
cal.set(2007, 11, 05);
task.setParameterValue("EndDate", cal.getTime());
task.setParameterValue("SubscriptionResult", new Integer(2));
task.setParameterValue("DorUserType", new Integer(0));
task.setParameterValue("TaxType", new Integer(2));
IRenderOption setting = new HTMLRenderOption();
setting.setOutputFileName("C:/temp/test.html");
task.setRenderOption(setting);
System.out.println("task: " + task.getRenderOption());
task.run();
task.close();
engine.shutdown();
System.out.println("Finished");
}
catch (EngineException ex) {
ex.printStackTrace();
}
}
}
I have included all the required libraries in corresponding
places.
Please some body help me..........
|
|
|
Re: Unable to run birt report from a Standalone java project [message #261015 is a reply to message #260880] |
Fri, 09 November 2007 10:53  |
Eclipse User |
|
|
|
Originally posted by: jasonweathersby.alltel.net
Kalyan,
It looks like the engine is not starting up. Try code similar to this:
Jason
import java.util.HashMap;
import java.util.logging.Level;
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.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
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.RenderOption;
public class RunAndRenderTask {
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
//System.setProperty("java.io.tmpdir", "c:/temp/test/testsampledb");
config = new EngineConfig( );
config.setBIRTHome(" C:\\birt\\birt-runtime-2_2_0\\birt-runtime-2_2_0\\ReportEngi ne ");
config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", (new Integer(3)));;
task.setParameterValue("Top Count", (new Integer(5)));
//task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/TopNPercent.html ");
options.setOutputFormat("html");
options.setHtmlRtLFlag(false);
options.setEmbeddable(false);
options.setImageDirectory("C:\\apps\\apache-tomcat-5.5.20\\webapps\\2.2\\images ");
options.setBaseImageURL("http://localhost:8080/2.2/images/");
//ImageHandlerTest
options.setImageHandler(new MyImageHandler());
//options.setImageHandler(new HTMLServerImageHandler());
//options.setImageHandler(new HTMLCompleteImageHandler());
//options.setBaseImageURL("http://localhost/imageGetter?");
task.setRenderOption(options);
//CancelReport cancelThread = new CancelReport( "cancelReport", task);
//cancelThread.start();
//long beginTime = System.currentTimeMillis();
task.run();
//long endTime = System.currentTimeMillis();
//long timeSpan = endTime - beginTime;
//System.out.println("Report Runtime: " + timeSpan);
//int teststatus = task.getStatus();
//if( teststatus == 4){
// System.out.println("Report was cancelled");
//}
task.close();
//Create task to run and render the report,
//task = engine.createRunAndRenderTask(design);
//task.setParameterValue("Top Percentage", (new Integer(3)));
//task.setParameterValue("Top Count", (new Integer(5)));
//task.validateParameters();
//task.setRenderOption(options);
//beginTime = System.currentTimeMillis();
//task.run();
//endTime = System.currentTimeMillis();
//timeSpan = endTime - beginTime;
//System.out.println("Report Runtime: " + timeSpan);
//teststatus = task.getStatus();
//if( teststatus == 2){
// System.out.println("Report Completed");
//}
//task.close();
engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
RunAndRenderTask ex = new RunAndRenderTask( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
private class CancelReport extends Thread
{
private IRunAndRenderTask rTask;
public CancelReport( String threadName, IRunAndRenderTask task){
super(threadName);
rTask = task;
}
public void run()
{
try{
Thread.currentThread().sleep( 100 );
rTask.cancel();
System.out.println("######Report Cancelled#######");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
Kalyan Garlapati wrote:
>
>
> Hi,
>
> I was able to execute my report from eclipse. But when i tried to
> execute it from a standalone java program(it is written in JBuilder), i
> got the following error.
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.birt.report.engine.api.ReportEngine.openReportDe sign(ReportEngine.java:111)
>
> at subsreqrequest.RRTest.main(RRTest.java:27)
> Can't load the report engine
>
> Here is my program
>
> package subsreqrequest;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.core.exception.*;
> import org.eclipse.birt.report.engine.api.EngineConfig;
> import org.eclipse.birt.report.engine.api.EngineException;
> import org.eclipse.birt.report.engine.api.HTMLRenderOption;
> import org.eclipse.birt.report.engine.api.IReportEngine;
> import org.eclipse.birt.report.engine.api.IReportRunnable;
> import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
>
> public class RRTest {
> public RRTest() {
> }
>
> public static void main(String[] args) {
> RRTest rrtest = new RRTest();
>
> try {
> EngineConfig config = new EngineConfig();
> config.setEngineHome("C:/birt-runtime-2_1_1/ReportEngine");
>
> System.out.println("EngineHome: " + config.getBIRTHome());
> IReportEngine engine = new ReportEngine(config);
>
> IReportRunnable design = engine.openReportDesign(
> "C:/sampreport/Subs.rptdesign");
>
> design.getReportName();
> IRunAndRenderTask task = engine.createRunAndRenderTask(design);
>
> java.util.Calendar cal = java.util.Calendar.getInstance();
> cal.set(2007, 10, 10);
> task.setParameterValue("BeginDate", cal.getTime());
> cal.set(2007, 11, 05);
> task.setParameterValue("EndDate", cal.getTime());
> task.setParameterValue("SubscriptionResult", new Integer(2));
> task.setParameterValue("DorUserType", new Integer(0));
> task.setParameterValue("TaxType", new Integer(2));
>
> IRenderOption setting = new HTMLRenderOption();
> setting.setOutputFileName("C:/temp/test.html");
> task.setRenderOption(setting);
> System.out.println("task: " + task.getRenderOption());
> task.run();
> task.close();
> engine.shutdown();
> System.out.println("Finished");
>
> }
> catch (EngineException ex) {
> ex.printStackTrace();
> }
> }
> }
>
> I have included all the required libraries in corresponding
> places.
>
> Please some body help me..........
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04823 seconds