Bullet-Proof Jasper Reports and PHP
Okay, so I got a fair bit of traffic about my last entry where I attempted to explain how I managed to get PHP to talk to Jasper through use of the PHP/Java Bridge instead of having to resort to running external programs through exec, which is undesirable for a number of reasons (including parameter passing and performance).
I’ve done a bit more work with Jasper using PHP and I can say that a few simple steps can make life infinitely easier.
First of all: Setting up and using the PHP/Java Bridge.
You don’t need to use the extension, there is a library written in pure PHP that you can use as a fall-back. When populating a report with Jasper, you don’t use that many Java calls so the reduced performance should not impact on your application too much. If you are calling a fair bit of Java from PHP, I would attempt to get the extension working as the performance is increased dramatically.
Here is a nice little function from the PHP/Java Bridge examples that detects if the extension is loaded and falls back to the native bridge if it isn’t available:
It assumes that you have the PHP implementation in the “java” directory. See the guide below for downloading this.
Second: Classpath is still screwy.
There is something about the bridge that I cannot figure out. Regardless of environment variables, they way you use java_require, settings in php.ini or any other setting this still seems to stuff up. There is one solution that I attempted to steer away from as I did not see it as ideal, however please believe me when I say that this single step will save you hours, if not days of frustration.
Put all the Jasper libraries into your jre lib/ext directory. Trust me.
I have got things tantalisingly close to working with other methods of making the libraries available to the bridge, and even succeeded on the odd occasion. However this is the only reproducible guaranteed way to get rid of those class woes once and for all.
By using the PHP implementation of the bridge and putting your jars into the lib/ext directory, you should be able to get this to work on any platform. I have got it working on Windows and Linux, but by removing any reliance on external settings this should work on pretty much any platform.
Third: Use the JDT compiler.
This little tid-bit of gold was dropped on my blog by Lucian, one of the primary contributors to Jasper’s continued development (thank you).
If you have the jdt-compiler jar in your lib/ext folder as well, the problem of java having a different running directory to that of PHP becomes a non-issue. Most importantly however, this removes the need to set environment variables!
With my previous approach to getting jasper working, I resorted to writing a wrapper class primarily because you can not set the “jasper.reports.compile.temp” and “jasper.reports.compile.class.path” through the bridge (it doesn’t work). Setting these gave the javac compiler the information it needed to compile the report, without them it failed horribly. The JDT compiler does all this stuff in memory, it is hot.
Lastly, the easiest way to get all the libraries required for running Jasper is to download and install iReport then grab them from the lib directory. Please pay attention to the licensing! Some of these libraries like the mysql connector are under the GPL so distributing it with a non-GPL product will be frowned upon.
Putting it all together.
After this work, compiling and running a report from PHP becomes a simple exercise in translating from the Java examples to PHP:
Note that you still need to use complete class names, otherwise you will get Class Not Found problems.
Okay, a quick guide to running Jasper from PHP:
- Setup the environment as per normal with PHP and Java (I use WAMP on Windows);
- Download the latest iReport software and install it on your workstation;
- Grab all of the files from “C:\Program Files\JasperSoft\iReport-2.0.2\lib” (version number will change) and copy them into your java’s lib/ext directory;
- Download the latest version of the PHP/Java Bridge with source and unzip it;
- Unzip the src.zip file (should be included in the download) and copy the contents of the “java” directory to your PHP app.
- If you want to use the stand-alone Java Server (easiest), grab the JavaBridge.jar from the ext directory (in the download) and copy it into the “java” directory you just placed in your PHP app.For production, you will probably want to use the Java extension and configure it to come up with your web server. There are a few configuration options here (including J2EE back-ends and the like), and the PHP/Java Bridge website explains how to get working with them.
- Start the Java backend (java –jar JavaBridge.jar). This will usually bring up a dialog asking what port to use, however you have command-line options as well if you are running headless.
- Try it out!!
Here is an example report: test.jrxml
And some example PHP code to compile, run it and send it to your browser: index.php.txt
Other things to note:
- Please cache the compiled version of your reports; otherwise you will be waiting for the report to compile every time you run one. I have some example code for doing this in my ReportGenerator class I used in my previous post.
Hopefully people will find this approach a little more straight-forward.
Enjoy!


October 29th, 2007 at 10:55 am
hey mate, no idea what you’re writing about but send us a your email when you have a chance
November 10th, 2007 at 5:14 am
Hi, i really liked your examples, i only had a question, i work in windows but i had to change my site to linux but i still can’t install the javabridge, well it’s run ok with simple java classes new Java(’java.util.HashMap’), or with classes like HelloWorld.class that don’t use external packages, but when i try to load a class that use jfreechart throw an exception that can’t find the classes, thats because they can’t find the .jars, im using fedora rc6.
Did you have a step by step installation for linux ?
i have to install a jdk or something before install the bridge ?
November 10th, 2007 at 9:05 am
Hi Mau,
I’d say that if you are able to get the base classes to work from the Bridge, it sounds like you have already got the jdk, bridge and everything setup correctly; you just need to sort out the classpath issues.
As I mentioned, your best bet it to copy the jars into the ext directory for your java. I’ve only used the Sun JDK on linux, so the ext directory for that is usually located here: /usr/java/latest/jre/lib/ext. I think the java that ships Fedora (gcj?) has the lib directory located here: /usr/share/java/ext
After throwing the jars in, it should just be a matter of restarting the server / bridge to get things working correctly.
November 21st, 2007 at 6:27 am
Could you, please, offer an example with a DataSource a MySQL connection.
I’m having a hard time figure this out as I have no Java experience…
November 21st, 2007 at 10:21 pm
Could you please give me a sample in PHP on how to link a MySQL specific database to a Jasper Report (I already got working a Jasper Report but with no source data).
Thanks, in advance!
November 22nd, 2007 at 9:05 am
Hi DanielP,
To get a data source in PHP, you just have to translate from the java. The Sun tutorial has some good examples to help get you started: http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
Note that I haven’t tried this code, but you should be able to connect with something like this:
$class = new JavaClass(”java.lang.Class”);
$class->forName(”com.mysql.jdbc.Driver”);
$driverManager = new JavaClass(”java.sql.DriverManager”);
$conn = $driverManager->getConnection(”jdbc:mysql://localhost/test?user=root&password”);
November 22nd, 2007 at 9:51 pm
Thanks a lot, it worked!
Now, I have a Jasper Report compiled dynamicaly and containing MySQL result right in PHP/Apache.
December 15th, 2007 at 11:15 pm
I got this error message :
Fatal error: Class ‘JavaClass’ not found
Thanks
December 17th, 2007 at 1:01 pm
Sounds to me like the Java extension was not correctly loaded in PHP.
Have a look over the checkJavaExtension function to make sure it worked okay, make sure that error reporting is setup to show warnings as it is likely that there is more going on behind the scenes. I am thinking that the include failed for some reason.
December 24th, 2007 at 9:21 pm
hi I got the following errors using ur example .my php error reporting is set to E_ALL and I think php/java bridge is also installed correctly.
pls help me.
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: Invoke failed: [[c:JasperExportManager]]->exportReportToPdfFile((o:JasperPrint)[o:JasperPrint], (o:String)[o:String]). Cause: net.sf.jasperreports.engine.JRException: Error trying to export to file : /var/www/html/jaspertest/output.pdf Responsible VM: 1.6.0_01@http://java.sun.com/” at:
#-11 net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:311) #-10 net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:126) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
#0 java.inc(255): java_ThrowExceptionProxyFactory->getProxy(10, ‘net.sf.jasperre…’, true)
#1 java.inc(471): java_Arg->getResult(true)
#2 java.inc(477): java_Client->getWrappedResult(true)
#3 java.inc(672): java_Client->getResult()
#4 java.inc(1783): java_Client->invokeMethod(9, exportReportToP…’, Array)
#5 java.inc(1907): java_JavaProxy->__call(’exportReportToP…’, Array)
#6 java.inc(2069): java_AbstractJava->__call(’expo in java.inc on line 218
December 26th, 2007 at 11:14 pm
Sounds to me like the permissions on your jaspertest folder are not allowing your JVM to write to the file. Try blasting it with chmod ““R 777 /var/www/html/jaspertest and see if that does the trick.
Of course, you should really have most of the files in the system as something more restrictive like 644, and then have the PDF generated into a tmp directory that has write permissions to help avoid security problems. But, at least this way you can rule the permissions issue out as a problem.
Let me know if this does the trick.
January 14th, 2008 at 9:39 am
Just wanted to say thanks… I got Jasper reports working, connecting to both MySQL and MS SQL Server over jdbc connections. You’re awesome!
January 18th, 2008 at 7:58 am
Thank you so much for a great article! I was wondering if I could get some advice from you or anybody who reads this.
I’m not a Java programmer, so I may be doing something wrong.
I can now compile, fill and export reports thanks to this article, but I have one report I need to view with the viewer applet (from the webapp demo in the Jasper Reports download). The applet is expecting a filled JasperPrint object, so I point the REPORT_URL parameter of the applet to my PHP script:
compileReport(realpath(”../test.jrxml”));
$fillManager = new JavaClass(”net.sf.jasperreports.engine.JasperFillManager”);
$params = new Java(”java.util.HashMap”);
$emptyDataSource = new Java(”net.sf.jasperreports.engine.JREmptyDataSource”);
$jasperPrint = $fillManager->fillReport($report, $params, $emptyDataSource);
header(”Content-type: application/octet-stream”);
$outputStream = new Java(”java.io.ObjectOutputStream”);
$outputStream->writeObject($jasperPrint);
$outputStream->flush();
$outputStream->close();
die();
?>
But the applet gives me back:
net.sf.jasperreports.engine.JRException: Error loading object from URL :http://192.168.60.16/jasper/applet/get_report.php
…
…
…
…
Caused by: java.io.StreamCorruptedException: invalid stream header:6F626A65
Do I need to convert the $jasperPrint object between PHP and Java somehow? Or does anybody have any other ideas?
Thanks again for the article and thanks in advance to anyone who may be able to help!
February 8th, 2008 at 4:26 pm
Ok
Finally got this to work. For some reason I had to explicitly set the classpath before running the JavaBridge.jar to point to the jasper etc jars.
export CLASS_PATH=/usr/share/java/jasperxxxx.jar;…jar;etc etc
then run
/usr/local/java/bin/java -jar /usr/share/java/JavaBridge.jar SERVLET:8080 3 mylogfile.log
How can I avoid having to explitly export my class path.
Do I need to extract all the jar files or can I set this up in a config file somewhere.
Putting all the jar files in the path of the jre did not help …
I would like to do this properly as this is for a production reporting server.
February 8th, 2008 at 5:08 pm
Hi agargan,
Basically you need to be able to make the java classes available to the java bridge one way or another.
The easiest way is to just throw them into your JRE lib/ext directory as I mentioned in this article, you can also set your classpath however I have had mixed results with this, sometimes it works, other times not, it depends on how your JVM is invoked.
Sometimes, you can extract the Jars and put the resulting paths in the same directory as the java application, but this does make things a little messier. I haven’t tried it with the bridge and Jasper.
If you are looking to setup a production server, it might be worth using the binary PHP / Java bridge extension and setting the JVM to start with the apache server. You will probably need to have the Jasper Jars in the ext directory for this to work however, as using the classpath options in php.ini did not work for me. This way you don’t have to use a script.
If you still can’t get the JVM to see the jasper libraries when started with apache, you might have some success using the wrapper class I mentioned in my last article.
Check out the website for installation options http://php-java-bridge.sourceforge.net/pjb/
February 8th, 2008 at 10:15 pm
I tried putting the jars in the jre/lib/ext dir and as I said this did not work.
[root@zugzug html]# export CLASS_PATH=/usr/share/java/jasperreports-2.0.4.jar
[root@zugzug html]# /usr/local/java/bin/java -jar /usr/share/java/JavaBridge.jar SERVLET:8080 3 javabridge.log
was how i got it to actually run and still be able to call the jasper reports but this is ugly. ;(
The JRE lib/ext dir I placed the jars in is the one that is used by the JavaBridge.jar according to the test.php shipped with the php-java-bridge package.
I am running on CentOS 5.1 fully patched.
had to get a fedora package to solve a dependancy for the rpm of php-java-bridge to install. (libgcj.8rh).
After creating the PHP module with the phpize of the devel package that ships with CentOS the module doesn’t load due to it being compiled under a newer phpapi (why this is I dunno I thought the devel and binary packages would be the same versions)
So hence I am using the Java.inc pure php lib instead of the php module.
At this stage I think I will be writing an init script to start and stop the JavaBridge.jar as a service.
I am going to set the CLASS_PATH in here before running starting the JavaBridge.jar.
Its working now but I am thinking maintenance will be yucky and I will be doing explicit CLASS_PATH mappings to the jar files including the jdbc drivers etc.
have not worked with Java for ages so I am learning anew the pain of it but I am very impressed by both Jasper and php-java-bridge …
Thank you very much for a great post its has been invaluable for solving an urgent reporting requirement at work.
May 1st, 2008 at 1:21 pm
Setup:
Windows
Tomcat 6
JasperServer 2.1 (installed on existing Tomcat server)
MySQL 5
JAVA 6 update 5
PHP/JavaBridge running from Tomcat server (not the JavaBridge.jar)
at first i tried putting all of the Jasper libraries (*.jar) from iReport/lib into jre/lib/ext folder. That made Tomcat unable to start properly, errors such as ClassNotFound and so on. That caused JasperServer’s default application not load. reading around found out that Tomcat server does not load well when the servlet.jar is somewhere where it’s not supposed to be, removed servlet.jar from the jre/lib/ext folder still received errors starting Tomcat. it was just not a good idea to put ireport/lib into jre/lib/ext when you’re running Tomcat 6. it messes up catalina classloader.
After quite some time, figured out that putting the right libraries not all into the Tomcat/lib folder not into jre/lib/ext did the thing.
JasperServer running smooth. PHP/Java bridge working fine.
so far the libraries that were copied to the tomcat/lib folder were:
jasper*.jar
common*.jar
itext*.jar
could be more. I’m not sure how many libraries are needed for jasper reports to run.
hopefully this helps for people with similar setup.
June 2nd, 2008 at 11:00 pm
I am new in linux and jasperreports
please some help here
fedora core 8
php 5.2.4
apache 2.2.8
java-bridge 5.2.2
java_home = usr/lib/jvm/java-1.7.0-icedtea-1.7.0.0/jre/bin
mssql database
I followed you tutorial and copied your index.php.txt.
All I get when I call it is a blank page.
Nothing
the only thing I see different is that my jasperreport is in a sub directory called reports.
Can you please help me with
Thanks again.
October 23rd, 2008 at 3:45 am
I have a very very simple report with one parameter called partnerId. I’m trying to use this parameter into the report query (which is defined inside the report). What I’m trying to do is something like
SELECT some fields
FROM partners
WHERE partners.`partnerId` = $P{partnerId}
But when i compile+execute the report from php i get a blank page. I tried removing the parameter from the query and all worked great, in fact the parameter is reaching report with the right value (i’ve tested it printing the parameter in the report).
Any advise on solving this problem? I’ve surfed the web but didn’t find anything of help. In fact i’ve also tried to write the parameter value as $P!{partnerId} because i’ve seen like that somewhere on the web, but that didn’t work either.
November 5th, 2008 at 3:30 am
Thanks a lot. Finally I got Jasper working.
November 6th, 2008 at 4:40 pm
hello,
i am trying to install php-java-bridge on xampp.But i am getting too confused .I am using
php-java-bridge_5.3.2.1.2_j2ee
xampp on windows, jasper server 3.0.0 and jdk 1.5
How do i install it?
April 15th, 2009 at 12:15 am
Hi Richard,
I have installed JasperReports 3.5 Pro, PHPJavaBridge. PHPJavaBridge is running properly. Where would I find
Jasper Libraries? When I run the PHP program given by you
I am getting following errors:
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: ReferenceClass failed: new JasperCompileManager. Cause: java.lang.ClassNotFoundException: JasperCompileManager VM: 1.6.0_13@http://java.sun.com/” at: #-25 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) #-24 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) #-23 java.lang.ClassLoader.loadClassInternal(Unknown Source) #-22 java.lang.Class.forName0(Native Method) #-21 java.lang.Class.forName(Unknown Source) #-20 php.java.bridge.SimpleJavaBridgeClassLoader.forName(SimpleJavaBridgeClassLoader.java:157) #-19 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:455) #-18 php.java.bridge.Request.handleRequest(Request.java:430) #-17 php.java.bridge.Request.handleRequests(Request.java:481) #-16 php.java.servlet.PhpJavaServlet.handleLocalConnection(PhpJavaServlet.java:190) #-15 php.java.servlet.PhpJavaServlet.doPut(PhpJavaServlet.java:227) #-14
Plese provide the cause of solution of error.
Your help will be highly appreciated.
Thanks in Advance,
Nitin Shelke & Hiren Patel
Global Funds Solutions
May 11th, 2009 at 4:05 pm
i have this error can anyone tell me how to solve it……
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\wamp\www\test.php on line 22
Warning: include(http://127.0.0.1:8080/Java.inc) [function.include]: failed to open stream: no suitable wrapper could be found in C:\wamp\www\test.php on line 22
Warning: include() [function.include]: Failed opening ‘http://127.0.0.1:8080/Java.inc’ for inclusion (include_path=’.;C:\php5\pear’) in C:\wamp\www\test.php on line 22
June 10th, 2009 at 9:23 pm
Setup:
Windows
PHP 5.1.6
JasperServer-pro-3.5-windows-installer
MySQL 5
php-java-bridge_4.2.2_j2ee
i have modified Apache2 httpd.conf file and php.ini file.In PHP.ini file i changed extension_dir,and i added extension=php_java.dll and “java” module.But i am getting a blank page.when i execute a program to get java properties, i am getting output like
Java version=Object id #23
Java vendor=Object id #22
OS=Object id #7 Object id #23 on Object id #22
Wednesday, June 10, 2009 at 4:52:24 PM Central Daylight Time
but i am not getting java properties.
if anybody have idea could u please help me.
Thanks in advance.
Regards
srikanth
June 19th, 2009 at 1:48 am
I installed the php-java-bridge but it gives me the following error:
——-
PHP Fatal error: Class ‘JavaClass’ not found in
——-
the line is
——-
$compileManager = new JavaClass(”net.sf.jasperreports.engine.JasperCompileManager”);
——-
What I do wrong?
Thank you
June 23rd, 2009 at 6:52 pm
Now I have the problem when running the example code(index.php.txt)
it’s show javax.servlet.ServletException: PHP Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: ReferenceClass failed: new net.sf.jasperreports.engine.JasperCompileManager
I think it cannot reference jasperreports java class. I work on linux server and copy lib(.jar) from iReport/ireport/modules/ext/ to:
- /tomcat5/common/lib/
- /webapps/JavaBridge/WEB-INF/lib/
- /java/jdk1.5.0_14/jre/lib/ext/(someone told for linux)
but it still doesn’t work. I am a newbie for java please someone help to share the idea. thanks
July 23rd, 2009 at 10:49 pm
By the way as of today PHP/Java Bridge
do not come as extension but the sites
says that it should be installed with tomcat
Any changes required for steps in this article ?
Can u take some trouble and give revised steps?
Thanks and best regards
July 30th, 2009 at 3:43 pm
I also get a blank page when I exportReportToPdfFile.
I think it is connection problem.
When I used
$emptyDataSource = new Java(”net.sf.jasperreports.engine.JREmptyDataSource”);
$jasperPrint = $fillManager->fillReport($report, $params, $emptyDataSource);
, the first page with null data fields is appear.
But when I used
$class = new JavaClass(”java.lang.Class”);
$class->forName(”com.mysql.jdbc.Driver”);
$driverManager = new JavaClass(”java.sql.DriverManager”);
$Conn = $driverManager->getConnection(”jdbc:mysql://localhost/mydb?user=root&password=abcd1234″);
$jasperPrint = $fillManager->fillReport($report, $params, $Conn);
Only blank pdf file is appear.
I tested the same procedure in jsp, the pdf is working well with data.
August 9th, 2009 at 11:41 pm
after lot of trial error I found out the solution for using jasper reports with PHP.
Simply copy java-Bridge.war file to Tomcats webappl dir.
Copy required jasper*.jar s to Tomcats lib dir.
Restart the tomcat server. (here I stumbled)
its very important since java newcomers like me have very little idea about installing java
application servers unless we restart the server you wont get bridge running. I tried many times copying and deleting the copied files and accidentally i found it working when I forgot to delete the copied files and shutdown the machine. Next day when I started I found java bridge working then jasper report worked fine.
Hope this helps
August 31st, 2009 at 2:43 am
Hi guys,
I got this error:
Fatal error: Unchecked exception detected in C:\xampp\htdocs\JasperReportPHP\java\Java.inc on line 131
in the line:
$report = $compileManager->compileReport(realpath(”test.jrxml”));
of the index.php file given by Richard. Any help is very much appreciated.
September 1st, 2009 at 10:58 pm
I am using PHP/Java Bridge to integrate jasper and my php application and this is the error I got:
Fatal error: Class ‘JavaClass’ not found in /var/www/index.php on line 85
September 2nd, 2009 at 7:53 pm
Hi Guyz
I am trying to accese java classes using php application. I have installed PHP/Java Bridge successfully and tested with http://localhost/phpinfo.php this is the link I’ve followed : http://www.flyninja.net/?p=69 .
on my /var/www/ directory I have put:
flyNinja();
echo ‘This is what is returned from the flyNinja method: ‘ . $fly;
@java_reset();
?>
and saved it with testbridge.php
AND AND my java class is:
public class phpJavaExample{
public static void main(String[] args){
//Don’t need a main method as we are calling it from php, this is only for compiling issues.
}
public String flyNinja() {
String ninja = “FlyNinja is a great resource for all your intellectual, technological and compulsive needs.”;
return ninja;
}
}
and saved by phpJavaExample under /var/www/classes/
so when http://localhost/testbridge.php on my browser this is the error I got
Fatal error: Call to undefined function java_require() in /var/www/testbridge.php on line 2
Can someone share with me what is going wrong
September 4th, 2009 at 4:23 pm
First of all, thank you for R.Johnson for giving out this tutorial. I have managed to implement some simple examples. But right now I’m stucked with subreports and scriplets.. anyone have any idea how to implement those two?
September 4th, 2009 at 4:34 pm
Ya, for people who got “JavaClass not found” error, it means that you haven’t manage to “require” the “Java.inc” file, that is either can be put on your php-application-root or in the servlet-root (for people using tomcat servlet like Raja S Patil’s implementation)
For people who got a “Java.inc on line 131″ error, it means that there is something wrong with the way you do the java things (maybe you called the wrong method on a Java class or anything). As php-java bridge doesn’t put out the Java error log on the screen, everytime you write a wrong java code, you’ll got this message instead of the actual error log.
For people who got “blanked” then usually it has something to do with your jasper report template (the .jrxml-s). An un-handled null-resulted query usually returns a blank report.
CMIIW, good luck everyone.
September 15th, 2009 at 12:44 am
I got the following error one for exportReportToPdfFile and another for exportReportToHtmlFile
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: Invoke failed: [[c:JasperExportManager]]->exportReportToPdfFile((o:JasperPrint)[o:JasperPrint], (o:String)[o:String]). Cause: net.sf.jasperreports.engine.JRException:
Error trying to export to file : /var/www/html/mysuite/tmp/7pXVdU
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: Invoke failed: [[c:JasperExportManager]]->exportReportToHtmlFile((o:JasperPrint)[o:JasperPrint], (o:String)[o:String]). Cause: net.sf.jasperreports.engine.JRException:
Error creating to file writer : myreport
What’s wrong with me?
September 18th, 2009 at 12:47 am
Well I want to thank the excellent article, and because of sharing his knowledge!
Meantime I have the next doubt:
When I tell to turn the archives of the example it takes place what does not find
Uncaught [[o:Exception]:”java.lang.Exception: ReferenceClass failed: new net.sf.jasperreports.engine.JasperCompileManager.
I tested already calling the classes java for the php and it is correct.
I installed the version iReport 3.6 version for windows. He would like being able if I have copy someone jasper*.jar so that so the above-mentioned class is found.
Please help me!
Apache 2.2.13
php 5.3
Tomcat 6
JavaBridge 552
Java version=1.6.0_16
Java vendor=Sun Microsystems Inc.
OS=Windows XP 5.1 on x86
September 18th, 2009 at 7:01 am
Hi! I have javabridge and when call function
$system = new Java(’java.lang.System’);
echo ‘Java version=’ . $system->getProperty(’java.version’) . ‘ ‘;
She is correct! But when call
$compileManager = new JavaClass(”net.sf.jasperreports.engine.JasperCompileManager”);
$report = $compileManager->compileReport(realpath(”relatorio.jrxml”));
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: Invoke failed: [[c:JasperCompileManager]]->compileReport((o:String)[o:String]). Cause: java.lang.ClassNotFoundException: Unresolved external reference: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource. — Unable to call the method, see the README section “Java platform issues” for details and DO NOT REPORT THIS PROBLEM TO THE PHP/Java Bridge MAILING LIST! VM: 1.6.0_16@http://java.sun.com/” at: #-6
Where I have to put the archives of jasper (*.jar) and what are they for which so I can call the class and through the object access the function of the class:
$compileManager = new JavaClass (” net.sf.jasperreports.engine. JasperCompileManager “);
September 25th, 2009 at 5:01 pm
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.
September 25th, 2009 at 6:03 pm
Hi Guyz
I have tested my Javabridge: http://localhost:8080/JavaBridge/ it is working on Tomcat and now I want to test the index.php.txt and test.jrxml examples that Rechards attached to his article.
So when running: root@ubuntu:/opt/apache-tomcat-6.0.20/webapps# php -d allow_url_include=On index.php
Fatal error: Class ‘JavaClass’ not found in /opt/apache-tomcat-6.0.20/webapps/index.php on line 85
How can I solve this problem of Fatal error: Class ‘JavaClass’
February 5th, 2010 at 2:44 am
Richard,
After many days of frustration and searching everywhere for answers . . . found your blog and everything came together! Thanks for sharing!!!!
February 14th, 2010 at 7:46 pm
Hi! I have one problem. When i run the program it works, but the pdf that I generate come out completely in blank, not even the image that it have…
Thank you guys!
February 26th, 2010 at 1:38 pm
Hello Richard,
Thank you for the post!
I have 1 problem right now. I am getting this message when I try to create the java object.
$compileManager = new Java();
Fatal error:
HTTP Status 403 -
type Status report
message
description Access to the specified resource () has been forbidden.
stucked!! pls help
March 5th, 2010 at 12:57 am
Great blog post - this works just great!
March 10th, 2010 at 5:23 pm
Hi,
I got the below error.. anybody pls help
Warning: fread() [function.fread]: Length parameter must be greater than 0 in C:\ms4w\Apache\cgi-bin\java\Java.inc on line 1018
Fatal error: in C:\ms4w\Apache\cgi-bin\java\Java.inc on line 859
March 26th, 2010 at 1:30 pm
Hi richard,
can u give me example how to create report with data from database with this php/java bridge? i’m using mssql 2008.. thanks in advance.
March 30th, 2010 at 3:35 pm
It is very good, I learn a lots.
thks.
April 2nd, 2010 at 4:14 pm
Hi Richard,
Thanks for this very good article, I appreciate it.
I got a problem, hope anyone can help me.
I set up everything followed this article, and running these commands as below is successful.
////////////////////////////
$system = new Java(”java.lang.System”);
$s = new Java(”java.lang.String”, “php-java-bridge config…”);
echo $s;
print “Java version=”.$system->getProperty(”java.version”).” “;
print “Java vendor=” .$system->getProperty(’java.vendor’).” “;
print “OS=”.$system->getProperty(” os.name “).” “.
$system->getProperty(”os.version”).” on “.
$system->getProperty(” os.arch “).” “;
// java.util.Date example
$formatter = new Java(’java.text.SimpleDateFormat’, “EEEE, MMMM dd, yyyy ‘at’ h:mm:ss a zzzz”);
//$formatter. “”;
print $formatter->format(new Java(”java.util.Date”));
//////////////////////////////
But I ran these commands as below, I got failure messages:
/////////////////////////
$emptyDataSource = new Java(”net.sf.jasperreports.engine.JREmptyDataSource”);
$jasperPrint = $fillManager->fillReport($report, $params, $emptyDataSource);
$outputPath = realpath(”.”).”/”.”output.pdf”;
$exportManager = new JavaClass(”net.sf.jasperreports.engine.JasperExportManager”);
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
header(”Content-type: application/pdf”);
readfile($outputPath);
//////////////////////////
The error message is as below:
///////////////////////////////////////////////////////
Fatal error: Uncaught [[o:Exception]:”java.lang.Exception: Invoke failed: [[o:JasperCompileManager]]->compileReport((o:String)[o:String]). Cause: net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: false (The system cannot find the file specified) VM: 1.6.0_19@http://java.sun.com/” at: #-12 net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172) #-11 net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152) #-10 net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:151) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #-8 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) #-7 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) #-6 java.lang.reflect.Method.invoke(Unknown Source) #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:990) #-4 php.java.bridge.Request.handleRequest(Request.java:417) #-3 php.java.bridge.Request.handleRequests(Request.java:500) #-2 php.java.bridge.http.ContextRunner.run(ContextR in C:\xampp\htdocs\pbxtra\cdr\include\bridge\Java.inc on line 195
///////////////////////////////////////////////
I have copied all *.jar in ireport/libs into jre6/lib/ext. But I still got these failure….
I am using XAMPP,jre6,ireport 3.7.1 and mysql.
Please give some advice.
Thanks very much。
April 22nd, 2010 at 12:06 am
Hi friends i tried this concept in windows xp using wamp server but didnt work. please help me how to configure.
June 24th, 2010 at 8:22 am
Very nice post, Richard. Thank you so much for writing this. You probably saved me several days of plowing through JavaBridge and JasperReport documentation.
I have this setup to work with JavaBridge, JasperServer Pro 3.7, and lampp (xampp for linux), running on top of CentOS. Setting up the JavaBridge was fairly straight-forward, and only involved dropping the JavaBridge.war file into the apache-tomcat/webapps dir. To get JasperReport working through the bridge, I did a ‘cp -u *.jar’ for all the jar files inside apache-tomcat/webapps/jasperserver-pro/WEB-INF/lib into apache-tombat/common/lib. Once you have the jars in place (as someone else mentioned) you do have to restart the server with ‘jasperctl.sh restart’. Note that in order to get Richard’s sample code to work you have to change ‘java/Java.inc’ to ‘JavaBridge/java/Java.inc’.
A word of warning: do not mix the jar files between JasperReport 3.7.3 and JasperServer 3.7, as they are incompatible and cause weird error about beans from Spring. I spend about a day scratching my head before I finally figured it out.
Good luck all!
July 17th, 2010 at 11:55 pm
Hi,
I found your blog at last minute before giving up, but still i am facing problem in installing php-java bridge. I tired to follow steps in the website of php-java bridge but i didn’t understand. I will say the steps i did correct me if any mistake i did.
I download javaBridge.war and kept that in the www folder of wamp and from command prompt i used
“java -classpath JavaBridge.war TestInstallation”
As said in the installation guide of PHP/Java Bridge but after that i got some some folders ext,java,test.php and result.html
After that i didnot understand step 2 and step3,
2.Download and install original Apache Tomcat software (or any other supported servlet engine) as a Windows or Unix service and copy JavaBridge.war to its autodeploy folder.
Auto deploy i am using wamp with php version of 5.3.0 and port of my localhost is 80.. Can you guide me what i need to do to make php/java bridge work.
July 18th, 2010 at 12:02 am
Hi,
I tired your PHP/Bridge installation also
# Download the latest version of the PHP/Java Bridge with source and unzip it;
# Unzip the src.zip file (should be included in the download) and copy the contents of the “java” directory to your PHP app.
But when i unzip the src i found 4 folders javax,php,META-INF,WEB-INF Again i didnot understand how to proceed from here.
September 9th, 2010 at 2:58 pm
Hi Jon,
Nice post above.
I have followed the link you provided for Php-Java Bridge and
I am able to trace that the bridge is working since I got
Java Version, its path inside a PHP Script.
The problem now is, when I give my custom *.Java file inside a
PHP script, the PHP is failing to recognize the *.Java file.
$system = new Java(”java.lang.System”);
The above works beautifully.
but,
$system = new Java(”myCustom”); // myCustom.java is my java file.
The above throws classNotFoundException.
Please shower some suggestions and let me walk the right path.
Thanks,
Vinay.
September 9th, 2010 at 6:41 pm
Hi Vinay,
You will need to compile your .java file to a .class or .jar file and then ensure this is accessible by the JVM.
Richard
September 9th, 2010 at 9:20 pm
Thanks Jon,
I confirm that I do have *.class file upon javac of *.java.
I even tried with *.jar of that *.java file.
Does not seem to work.
_vinay