Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Unable to include report library at run time
hkseeram
We are currently using BIRT2.3.1 until now no problems. We use the following code to include report library at run time and it is working fine in BIRT2.3.1.
report.includeLibrary(reportLibPath, ReportConstants.COMMON_LIB_NAMESPACE);
We upgraded to BIRT3.7 and in this release in the report output we don?t see any objects that were inherited from the report library. I am getting ?report library libs/CommonRepotLib.rptlibrary not found? error message.
Any idea why it is working in BIRT2.3.1 but not in BIRT3.7?
Please see the following snippet of the code that we used to include library:
EngineConfig config = new EngineConfig();
config.setLogConfig(configProps.getProperty("logDirectory"), Level.ALL);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
reportEngine = factory.createReportEngine( config );
IReportRunnable runnable = reportEngine.openReportDesign(new ClassPathResource(rptDesign).getInputStream());
IRunAndRenderTask runAndRenderTask = reportEngine.createRunAndRenderTask(runnable);
ModuleHandle report = runnable.getDesignHandle().getModuleHandle();
rptLib = getApplicationConfiguration().get(ReportConstants.LIB_ROOT_DIR) ;
//report.setResourceFolder(getApplicationConfiguration().get(ReportConstants.REPORT_ROOT_DIR));
//report.includeLibrary(rptLib, "CommonReportLib");
/*List<LibraryHandle> libList = report.getAllLibraries();
for (LibraryHandle lib:libList) {
report.includeLibrary(lib.getFileName(), "Template");
}*/
HTMLRenderOption htmlRenderOption = new HTMLRenderOption();
htmlRenderOption.setOutputFileName(fileWithFullPathInfo);
htmlRenderOption.setOutputFormat(msg.getOutputFormat());//ReportConstants.EXCEL_OUTPUT_FORMAT);
runAndRenderTask.setRenderOption(htmlRenderOption);
runAndRenderTask.run();
runAndRenderTask.close();
Also please see the report design file and library files are attached here.
Thanks for your help
Hari
Find more posts tagged with
Comments
JasonW
Can you try something like:
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.EngineException;
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.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.TableHandle;
import com.ibm.icu.util.ULocale;
public class AddTableFromLib {
public void runReport() throws EngineException
{
IReportEngine engine=null;
IDesignEngine dengine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setLogConfig(null, Level.FINE);
config.setResourcePath("C:\\work\\workspaces\\3.7workspaces\\3.7.0workspaces\\BIRT Metal\\APIs\\resources");
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
DesignConfig dconfig = new DesignConfig( );
IDesignEngineFactory dfactory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dengine = dfactory.createDesignEngine( dconfig );
IReportRunnable design = null;
//Open the report design
SessionHandle session = dengine.newSessionHandle( ULocale.ENGLISH );
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
report.includeLibrary(
"test.rptlibrary", "test" ); //$NON-NLS-1$ //$NON-NLS-2$
LibraryHandle lh =report.getLibrary( "test" ); //$NON-NLS-1$
TableHandle deh3 = (TableHandle)lh.findElement("myTable");
ElementFactory elementFactory = report.getElementFactory();
TableHandle ldeh3 =(TableHandle) elementFactory.newElementFrom(deh3, "myTable1");
report.getBody().add(ldeh3);
//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/desample/ModifiedTopNPercent.html");
options.setOutputFormat("html");
options.setImageDirectory("resample/images");
//options.setBaseImageURL(baseImageURL)
task.setRenderOption(options);
task.run();
task.close();
session.closeAll(false);
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
AddTableFromLib ex = new AddTableFromLib( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Jason
hkseeram
Jason,
Thanks for your response. I was able to fix by adding the following code:
List<LibraryHandle> libList = report.getAllLibraries();
for (LibraryHandle lib:libList) {
lib.setFileName(getApplicationConfiguration().get(ReportConstants.REPORT_ROOT_DIR)+lib.getFileName());
report.dropLibrary(lib);
report.includeLibrary(lib.getFileName(), lib.getNamespace());
}
Thanks
Hari