Home DevShare Deploying BIRT Reports

Calling BIRT From PHP

Share

by JasonW

DevShare - 100 postsForum - 2,000 postsCommunity Advisor
Posted 26 Feb 2009 - 01:13 PM

(1)  (0)   (13868 views)

This article, published on TheServerSide, and related code, explain how to call BIRT from a PHP application using the open source PHP/Java Bridge.

Birt Version:-2.5

This WAR contains the open source PHP/Java Bridge and BIRT plugins.  It also has several examples of calling the BIRT Engine, including BIRT Library Usage and Drill Through.

Information on the PHP/Bridge can be found at: http://php-java-bridge.sourceforge.net/pjb/. The PHP/Bridge and docs can also be downloaded from  http://sourceforge.net/project/showfiles.php?group_id=117793

BIRT 2.3.2 is included as part of the 5.5.4.1 documentation download.  The attached war includes BIRT 2.6.0. 

Article explaining the examples contained in the WAR is located at http://www.theserverside.com/tt/articles/article.tss?l=IntegratingBIRTwithPHP

Deploy the WAR and enter the url http://localhost:8080/JavaBridge/index.php to see a list of examples.
Next you can create a directory under you web server that is running PHP and copy all the PHP pages and report designs from the war to this new location.  Also copy the java directory that is contained the JavaBridge.war/java.

for example

htdocs/myphpbirt/java
contains a java directory with all the JavaBridge include files

JDBC Drivers

Use one of the following methods

1 - Place JDBC drivers in the exploded jar

JavaBridgeWEB-INFplatformpluginsorg.eclipse.birt.report.data.oda.jdbc_2.3.1.v20080827drivers

directory.  If you are using BIRT 3.7 or higher, just copy your driver to the WEB-INF/lib directory.

2 - change the BirtEngine.java class file in the birtEngine.jar to add the following code:

EngineConfig config = new EngineConfig();

config.getAppContext().put("OdaJDBCDriverClassPath", "locationofdirectorycontainingdrivers");

3- add the following to the PHP examples prior to running a report

$birtReportEngine->getConfig()->getAppContext()->put("OdaJDBCDriverClassPath", $here . "/jdbc/"); and put your drivers in the jdbc directory.

BIRT EventHandlers and extending Classpath

To add event handlers or extend the classpath set the appcontext variable "webapplication.projectclasspath" with full classpath to the jars you need to add.  See JDBC drivers step 2 or 3 to see how to do this.

config.getAppContext().put("webapplication.projectclasspath", "c:/myjars/jar1.jar;c:/myjars/jar2.jar");


If you wish to change the version of BIRT (valid only for BIRT 2.6.2 or less), do the following:

download the BIRT runtime for the version you need.

extract the attached WAR and and replace the WEB-INF/platform/plugins and WEB-INF/platform/config directories with the BIRT runtime download/ReportEngine/plugins and /ReportEngine/configuration directories.  Replace the WEB-INF/lib jars for the specific version of BIRT you are using.  Verify that the WEB-INF/platform/confi directory only contains a config.ini before redeploying the WAR.

Depending on the version of BIRT you use you may need to rebuild the birtEngine.jar which contains the BirtEngine.class.  The source is in the jar.  You may also need to update the examples.

 

If you wish to change the version of BIRT (valid only for BIRT 3.7.0 or greater), do the following:

download the BIRT runtime for the version you need.

extract the attached WAR and and delete the WEB-INF/platform directory.  Replace the WEB-INF/lib jars for the specific version of BIRT you are using.  To do this delete all the jars in the WEB-INF/lib except the following:

script-api.jar
php-script.jar
php-servlet.jar
lucene.jar
jaxrpc.jar
birtEngine.jar
JavaBridge.jar

Next copy all the jars from the runtimedownload/reportengine/lib directory into the WEB-INF/lib.

If you are using a JDBC driver jar just put it in the WEB-INF/lib directory.

Depending on the version of BIRT you use you may need to rebuild the birtEngine.jar which contains the BirtEngine.class.  The source is in the jar.  You may also need to update the examples.

 Render Note: Make sure for every render task (not RunAndRender) you run you close the report document.

$task = $birtReportEngine->createRenderTask($document);

.

.

$task->render();
$document->close();
$task->close();

OpenJDK note:  If you are using OpenJDK version 6 or 7 a different version of Rhino is included in the jre/lib directory.  You will either need to remove the jar or replace it with the version BIRT uses. See the following bugzilla entry for the OpenJDK http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=179.


Forum - 1 post

gte451f

Posted: 08 Mar 2009 - 05:44 PM

This is super cool! Used in conjunction with Jason's article here: http://www.theserverside.com/tt/articles/article.tss?l=IntegratingBIRTwithPHP But one thing is missing, how can we call the AJAX report viewer from PHP? Great work Jason!

Forum - 500 postsBlog - 50 postsDevShare - 200 postsCommunity Advisor

Virgil

Posted: 09 Jul 2009 - 03:41 PM

Since the BIRT Viewers use JSP, you can integrate these with URLs by deploying the BIRT Viewer to a Tomcat somewhere. You can also use the JavaScript API to more deeply integrate BIRT reports into a PHP page.

Forum - 500 postsBlog - 50 postsDevShare - 200 postsCommunity Advisor

Virgil

Posted: 09 Jul 2009 - 03:41 PM

The JavaScript API is explained better at http://www.birt-exchange.org/wiki/GSG:Getting_Started_with_BIRT_JavaScript_API/
 
Filter More