Long Live Open Source Software !!

If you make some web applications with PHP, sometimes you don’t know how to create a good report. Maybe you’ll create another application written in VB combined with Crystal Report like i did in my previous project.:mrgreen:.But now there is an alternative to create a good report in PHP. “How will you do that?”, you’ll say that to me after read this introduction.

I will use JasperReport here to create my report. “Hey, JasperReport is based on Java, how can you use that in you PHP application?”. Don’t worry guys, there is a good tool outside there so you can use JasperReport in your PHP Application. That tool is called PHP/Java Bridge. PHP/Java Bridge allow you to use any Java class in your PHP Application. And with this bridge, you can create a report from php application with JasperReport. I will show you how to install and setup PHP/Java Bridge and JasperReport in your linux system now. Actually this tutorial is based on this post by Richard Johnson. And i make the tutorial for linux and with newer iReport.

  1. Install and download php and java into your system.
  2. Download the latest iReport software from here, and install it. Please download the software, not the netbeans plugin.
  3. Copy all files from [iReport home]/ireport/modules/ext/ to JAVA_HOME/jre/lib/ext/
  4. Download the latest version of the PHP/Java Bridge with source from here and extract it.
  5. Unzip the src.zip file (should be included in the download) and copy the contents of the “java” directory to your PHP application.
  6. Find JavaBridge.war and place it in some directory.
  7. Run the bridge with java -jar JavaBridge.war TestInstallation, FYI, i stop this bridge using pkill.:mrgreen:
  8. Here is Richard Johnson sample application and his sample report created by iReport so you can try your installation.

C’mon try it yourself and give any comment about this tutorial below.

Reblog this post [with Zemanta]
Share this post here:
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us

Maybe you like this post too : [Tutorial] Generate Model Class with CRUD in CodeIgniter and MySql

Recent Top Story :

Recent Search :

23 Responses to “[Tutorial] Create Report in PHP with JasperReport in Linux”

  1. zulkifli Says:

    hm, if i want to use the report, is it needed to know about java language? but this stuff is a cool one..

    Reply

    baskoro Reply:

    of course, because Jasper is basically written with java and actually it is a java library.
    you can see the example if you’re confused

    Reply

  2. KS Tan Says:

    Hi, Currently I’m testing the java-php-bridge with you sample application, seems like having some problem. Below is the error message.

    ( ! ) Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: ReferenceClass failed: new net.sf.jasperreports.engine.JasperCompileManager. Cause: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JasperCompileManager VM: 1.6.0_13@http://java.sun.com/” at: #-15 java.net.URLClassLoader$1.run(URLClassLoader.java:200) #-14 java.security.AccessController.doPrivileged(Native Method) #-13 java.net.URLClassLoader.findClass(URLClassLoader.java:188) #0 /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc(259): java_ThrowExceptionProxyFactory->getProxy(1, NULL, false) #1 /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc(411): java_Arg->getResult(false) #2 /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc(414): java_Client->getWrappedResult(false) #3 /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc(603): java_Client->getInternalResult() #4 /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc(2055): java_Client->referenceO in /home/kstan/Desktop/php-java-bridge-5.2.0/server/META-INF/java/Java.inc on line 222

    Reply

    Sumair Rana Reply:

    First of all this post is more informative than Richard one.

    I got the same problem and thankfully i managed to get rid of it.

    If you see the error, the compiler is unable to find the libraries of JasperReport.

    I used apache tomcat for JavaBridge.WAR file. I deployed it into the tomcat server. Then i copied all the jar files from \Program Files\Jaspersoft\iReport-3.7.0\ireport\modules\ext directory TO \tomcat\webapps\JavaBridge\WEB-INF\lib directory.

    Restart tomcat server so that it picks all the jar files. And it worked ;-)

    Reply

    santhi Reply:

    with this step my tomcat server is not working at all. can u provide me the solution
    thanks

    Reply

    Sumair Rana Reply:

    To be honest this is what I did and it worked for me. Below are the detailed steps I followed:

    - After installation of your tomcat server, Go to the page http://localhost:8080/. This must take you to the Tomcat web server homepage.
    - Go to the link ‘Tomcat Manager’ on the left bar under ‘Administration’ section. Use the Tomcat admin/manager user logon details to login to this section.
    - Go to the section ‘WAR file to deploy’ and browse to the directory where you have unzipped the PHP/Java bridge files. Open the ‘JavaBridge.war’ file.
    - Click ‘Deploy’ button and this will install the PHP/Java bridge module on the Tomcat web server.

    Configure Jasper Reports for PHP environment
    - Stop the Tomcat web server.
    - Copy all the files from Jasper Report installation directory\ireport\modules\ext folder to Tomcat web server installation directory\webapps\JavaBridge\WEB-INF\lib directory.
    - Copy the MySQL JDBC connector file from Jasper Report installation directory\ ide10\ modules\ext folder to Tomcat web server installation directory\webapps\JavaBridge\ WEB-INF\lib directory.
    - Copy the complete folder java from Tomcat web server installation directory\webapps \JavaBridge\ directory on to the PHP web server under htdocs folder (You need to do that if your PHP code does not link up with the bridge).
    - Start the Tomcat web server. This will reload the PHP/Java bridge module with all the libraries copied in above steps. The module is now ready to accept requests from PHP environment.

    Hopefully this will work for you.

    Reply

    tikeshwar sahu Reply:

    How can i do it with tomcat please i need step by step tutorial if u can post.
    Thanx

    Reply

  3. guatemala Says:

    hello. where can i found the src.zip? I’ve downloaded the tar.gz package

    Reply

    baskoro Reply:

    download php-java-bridge_5.4.4.2_documentation.zip and find the src.zip inside that archive

    Reply

  4. Tron Says:

    I’m using GoDaddy server. I can not install anything in it. How do I use jasperreport?
    Thanks

    Reply

    baskoro Reply:

    i think it’s impossible if you can’t install anything in your server.
    maybe you can try to use JasperServer

    Reply

  5. KOMUNITAS PELAJAR ILMU KOMPUTER INDONESIA Says:

    NIce post…

    Reply

  6. Spoko Says:

    Thanks guyz I understand almost all the steps for setting up the JavaBridge but I am getting confuse when I get to number 5 of ur article. I manage to unzip src.zip file but which PHP application I must copy the “java” content to. Is it the JavaBridge.war or something else.

    5. Unzip the src.zip file (should be included in the download) and copy the contents of the “java” directory to your PHP application.

    AND whem runnning this command: root@ubuntu:/var/www# java -jar JavaBridge.war TestInstallation
    Failed to load Main-Class manifest attribute from
    JavaBridge.war

    Can someone help me.

    Reply

    baskoro Reply:

    I mean PHP Application is the directory where your php files were located

    Reply

  7. kstan_79 Says:

    My company’d develop a PHP class convert which can read iReport .jrxml and generate report on the fly. It is open source base on FPDF! Feel free to try.
    http://www.simit.com.my/?q=phpjasperxml

    However I’m not active in here, you can leave comment in the forum link at the home page.

    Reply

    baskoro Reply:

    it seems interesting, let me try it :)

    Reply

    kstan Reply:

    So how it work? Good for you?

    Reply

  8. Sachin Durge Says:

    Very Informative article, Its a good to see if you could upload any live demo example.
    Thanks in advanced

    Reply

  9. kstan Says:

    Hi Sachin Durge,
    The live demo is already in the website.

    Reply

  10. santhi Says:

    i m not getting the src.zip folder after download and how to run the sample application.

    as i am a fresher and don’t know about java i m not getting it.

    can any body help me.

    thanx

    Reply

  11. santhi Says:

    hi

    i am trying to run the given sample application but i am getting the following error:

    ( ! ) Fatal error: This PHP SAPI requires a JEE or SERVLET back end. Start it,define (‘JAVA_SERVLET’,true); define(‘JAVA_HOSTS’,…); and try again. in D:\Anil\Development\php\php5\htdocs\sample_report\java\Java.inc on line 1237
    Call Stack
    # Time Memory Function Location
    1 0.0007 360968 {main}( ) ..\sample_report.php:0
    2 0.0144 1596256 java_class->java_class( ) ..\sample_report.php:86
    3 0.0144 1596256 __javaproxy_Client_getClient( ) ..\Java.inc:2014
    4 0.0144 1598112 java_Client->java_Client( ) ..\Java.inc:1584
    5 0.0145 1599968 java_Protocol->java_Protocol( ) ..\Java.inc:319
    6 0.0145 1599968 java_Protocol->createHandler( ) ..\Java.inc:1262
    7 0.0146 1602608 java_Protocol->createSimpleHandler( ) ..\Java.inc:1255
    8 5.0146 1603520 trigger_error ( ) ..\Java.inc:1237

    can any one provide me a solution for this.

    thanks

    Reply

  12. Amit Says:

    How to replace
    $emptyDataSource = new Java(“net.sf.jasperreports.engine.JREmptyDataSource”);

    with connection to MySQL database?

    Reply

  13. user11 Says:

    You may try VIEWidget for Javascript PHP or ASP.NET or Java.
    It works with all major browers.

    It is a javascript-programmable report & technical drawing generator and print preview control.
    You may use VIEWidget to generate reports or technical drawings,
    display the results in a scrolling and zooming viewer on your web page and then print it.
    It is a very flexible and productive RAD tool as it lets you freely draw tables or
    other objects at arbitrary x-y coordinates. It can generate sophisticated reports that are
    difficult or impossible to create with a static report writer or conventional report generator.

    Below is a simple Hello World example for two print-preview pages
    with page footers for page numbering:

    //get length unit
    var INCH = control1.getInch();

    //create document
    control1.startDoc();

    control1.drawString(1*INCH, 1*INCH, “Hello World from Page 1″);
    control1.drawPageFooter(“Page 1″,”align=center”);

    //…draw other stuff here

    //create 2nd page
    control1.newPage();
    control1.drawString(1*INCH, 1*INCH, “Hello World from Page 2″);
    control1.drawPageFooter(“Page 2″,”align=center”);

    //…draw other stuff here

    //end document
    control1.endDoc();

    //preview first page (page index=0)
    control1.setCurrentPage(0);
    control1.preview();

    VIEWidget link:
    http://hexatech.com/viewidget

    Reply

Leave a Reply