Logo Background RSS

Installing the PHP Java Bridge in Ubuntu (Gutsy Gibbon)

  • Written by vinuvinu 25 Comments25 Comments Comments
    Last Updated: November 22nd, 2007

    If you’re looking for the easiest way to install the PHP Java Bridge in Ubuntu, follow these simple steps:

    If you don’t have Java Installed on your machine, enable the multiverse option in your Software Sources and run

    sudo apt-get install sun-java6-jre sun-java6-fonts sun-java6-jdk sun-java6-plugin
    sudo update-java-alternatives -s java-6-sun

    Download the PHP Java bridge deb files from Sourceforge.

    Head over to the directory where you’ve downloaded this deb file, and fire the following commands:

    sudo apt-get install liblucene-java libitext-java
    sudo dpkg -i php-java-bridge_4.3.0-1_i386.deb

    Once the php-java-bridge deb file is installed, apache will be automatically restarted. If apache doesn’t restart automatically, you can restart apache with the following command:

    sudo /etc/init.d/apache2 restart

    How do you check if the PHP Java bridge is installed?
    Run the phpinfo() command in php. This should give you the details of the PHP Java bridge extension under the Java Heading. Now you’re ready to run Java code in PHP :)

    Now head over to the following link and check out the second part of the tutorial to get started on PHP and Java.
    http://www.hiveminds.co.uk/node/3172

    More on the PHP Java bridge over at: http://php-java-bridge.sourceforge.net/

    Updates:

    Here’s another Article which shows how to bridge PHP an Java in Windows using Apache Tomcat:
    http://www.hiveminds.co.uk/node/3814

    Bookmark and share:
    • del.icio.us
    • Digg
    • StumbleUpon
    • BlinkList
    • blogmarks
    • Furl
    • Slashdot
    • Spurl
    • Technorati
    • YahooMyWeb
    • description
    • Facebook
    • Google
    • Live
    • Ma.gnolia
    • NewsVine
    • Reddit
    • TwitThis

Advertisement

25 Comments
  1. #1 vinu
    November 22nd, 2007 at 6:43 pm

    These instructions should work on Fiesty Fawn too.

    Post ReplyPost Reply
  2. #2 joomla
    November 30th, 2007 at 1:49 am

    Thx for tip!

    Post ReplyPost Reply
  3. #3 Nicolas Dezorthes
    December 4th, 2007 at 11:56 pm

    No working for me, i’v got this error on install :
    php-java-bridge depend of libc6 (>= 2.3.6-6) but the version of libc6 on the systeme is 2.3.6-0ubuntu20.5.
    No version of libc6 more recent seems available, ay idea to fix this problem?

    Post ReplyPost Reply
  4. #4 vinu
    December 5th, 2007 at 8:53 am

    Nicolas,
    The newer versions of Ubuntu ship with libc6 of the required version. Which version of Ubuntu are you currently running?

    Post ReplyPost Reply
  5. #5 Nicolas Dezorthes
    December 7th, 2007 at 12:43 am

    I’am on Ubuntu Dapper.

    Post ReplyPost Reply
  6. #6 Charles Shaffer
    June 4th, 2008 at 1:50 am

    I installed the Java Bridge per instructions and it seemed to go fine, but when I run a test I get this error.

    Fatal error: Class ‘java’ not found in /var/www/cs_dev/validate_part.php on line 8

    Code:
    $U2 = new java(’com.ntnbower.t4mutil’);

    The U2 object in the com.ntnbower.t4mutil package ahs been tested and works fine when called from another java class (with main).

    Does PHP need to be recompiled with the with-java directive? Or does the bridge make that unnecessary.

    Post ReplyPost Reply
  7. #7 vinu
    June 4th, 2008 at 10:53 am

    Charles,
    Are you using the PHP which came along with the Ubuntu repositories or did you manually compile PHP?
    If you used the Ubuntu repositories and followed the steps above it should work as is without having to recompile PHP.
    Just get your phpinfo() and see if you see Java listed in the list of extensions.

    Post ReplyPost Reply
  8. #8 Charles Shaffer
    June 4th, 2008 at 7:20 pm

    vinu,

    Yes. We are using the PHP that came with the Ubuntu install. PHPINFO says Java Support is enabled and the status is running. But java_home says no value. I wonder if the problem is with the java install. The error says the class Java is not found. I downloaded the latest Java from Sun as a self-extracting file. Was that unnecessary?

    Post ReplyPost Reply
  9. #9 Charles Shaffer
    June 4th, 2008 at 8:53 pm

    OK. Downloading the self-extracting java was a mistake. Our Linux guy helped me get rid of the self-extracting version of Java and we reinstalled the apt-get versions of java and the java bridge. PHP is aware of java and the status is running. It still doesn’t find the java class though. I just have a feeling this is an environment issue (PATH, CLASSPATH, ?) but I don’t know what the problem is. Do you need to import java somehow?

    Post ReplyPost Reply
  10. #10 vinu
    June 4th, 2008 at 9:36 pm

    Charles,
    I missed out one more point to ask. Did you set the path to the class files in your php code ? You can do that by using:

    java_require(”/path/to/your/classfiles/”);
    $U2 = new java(’com.ntnbower.t4mutil’);
    …………..
    …………..

    Post ReplyPost Reply
  11. #11 Charles Shaffer
    June 4th, 2008 at 9:41 pm

    By the way, if it matters we are using Feisty Fawn.

    Post ReplyPost Reply
  12. #12 Charles Shaffer
    June 5th, 2008 at 12:48 am

    Vinu,

    Progress. Sort of. When I add the require_java() statement the java object seems to be created OK, but there is an error further on.

    With this code:
    java_require(”/var/www/cs_dev/com/ntnbower/t4mutil/U2.class”);
    $U2 = new java(’U2′);
    $result = $U2->IsValidPartNumber($partnumber);
    if($result) print “Found”; (line 13)
    else print “Not Found”;

    This error:
    Parse error: syntax error, unexpected T_STRING in /var/www/cs_dev/validate_part.php on line 13

    With the require_java line commented out the error occurs when creating the new U2 object, which makes sense.

    Do you see why the require_java call is causing the T_STRING error?

    Thanks.

    Post ReplyPost Reply
  13. #13 Charles Shaffer
    June 5th, 2008 at 2:35 am

    More progress sort of.

    I discovered that by changing the quotes in the require_java statement
    java_require(’/var/www/cs_dev/com/ntnbower/t4mutil/U2.class’);

    I got rid of the parser errors.

    At run time I got
    Fatal error: Call to undefined function java_require() in /var/www/cs_dev/validate_part.php on line 9

    Do I need to set a path to somewhere?

    Post ReplyPost Reply
  14. #14 vinu
    June 6th, 2008 at 12:43 am

    Ok. Here’s my guess Charles - This line may be the cause:
    $result = $U2->IsValidPartNumber($partnumber);
    If the parameter is defined as integer in Java, PHP is unable to send $partnumber to Java, since it’s taken as a string.
    Try:
    $result = $U2->IsValidPartNumber($partnumber+0);
    Which will implicitly change the datatype to integer. Leave the java_require with the double quotes:
    java_require(”/var/www/cs_dev/com/ntnbower/t4mutil/”);

    “This bridge does not convert data dynamically like the core PHP engine does. You must do type conversion in your PHP code.”
    More information on this over at:
    http://dev2dev.bea.com/pub/a/2007/02/php-java-bridge.html

    Post ReplyPost Reply
  15. #15 Charles Shaffer
    June 10th, 2008 at 8:07 pm

    Hello vinu,

    I got side tracked for a while, but I’m back on the PHP-Java Bridge now. I have created a jar file called U2web.jar and put it in /usr/lib/jclass/ directory. /usr/lib/jclass/U2web.jar is in the CLASSPATH. In a standard java program I import import com.ntnbower.t4mutil.*; and this works fine.

    In the php code I include
    java_require(’/usr/lib/jclass/U2web.jar’); When I create the new object I use
    $U2 = new Java(’com.ntnbower.t4mutil.U2′);

    It fails on test and I get this error
    Unresolved external reference: java.lang.NoClassDefFoundError: asjava/uniobjects/UniSessionException. — Unable to call constructor, see the README section “Java platform issues” for details

    Do you know where I could find the README this refers to?

    Post ReplyPost Reply
  16. #16 vinu
    June 10th, 2008 at 11:28 pm

    Hi Charles,
    Change your Java require line to :
    java_require(’/usr/lib/jclass/’);
    It just needs the path to the class file. The jar file should not be specified in the the java_require line.

    Post ReplyPost Reply
  17. #17 Charles Shaffer
    June 11th, 2008 at 12:03 am

    vinu,

    Sorry for all of the questions.

    After changing the java_require to
    java_require(”/usr/lib/jclass/”);

    get this error
    CreateInstance failed: new com.ntnbower.t4mutil.U2. Cause: java.lang.ClassNotFoundException: Could not find com.ntnbower.t4mutil.U2 in java_require() path. Please check the path and the SEL and File permissions

    The class is in a jar file called U2web.jar jar tvf U2web.jar
    0 Tue Jun 10 13:10:58 CDT 2008 META-INF/
    71 Tue Jun 10 13:10:58 CDT 2008 META-INF/MANIFEST.MF
    1931 Tue Jun 10 13:10:22 CDT 2008 com/ntnbower/t4mutil/U2.class

    Permissions on the jclas directory are 755

    Don’t know what SEL is referring to.

    PHP code
    IsValidPartNumber($partnumber);
    print “Hello”;
    ?>

    Just trying to get past the instantiation at this point.

    Post ReplyPost Reply
  18. #18 Charles Shaffer
    June 11th, 2008 at 1:43 am

    vinu,

    Well I think it is working now. I had to put a reference in the java_require to a class that is imported in the class I developed.

    java_require(”/usr/lib/jclass/U2web.jar;/usr/lib/jclass/asjava.zip”);

    Thanks for all of your help.

    Post ReplyPost Reply
  19. #19 vinu
    July 14th, 2008 at 1:08 pm

    Here’s another Article which shows how to bridge PHP an Java in Windows using Apache Tomcat:
    http://www.hiveminds.co.uk/node/3814

    Post ReplyPost Reply
  20. #20 Slei
    August 14th, 2008 at 12:48 am

    Hi,
    I installed the php-java-bridge , but still having this error:
    Fatal error: Class ‘Java’ not found

    I didn’t install PHP5 from .deb package, I compiled the source to install PHP5 and Apache2.

    What I have to do? do I have to recompile PHP5 with Java, but when I run ./configure –help there is no –with-java option in PHP5….

    Thanks for your help.

    Post ReplyPost Reply
  21. #21 vinu
    August 19th, 2008 at 9:21 pm

    Slei,
    It looks like PHP cannot find Java. Since you’ve used custom compiled versions of PHP, the installer may not have updated your PHP.ini.
    The following link may be useful for you:
    http://www.raditha.com/php/java.php

    Post ReplyPost Reply
  22. #22 dbigand
    October 5th, 2008 at 10:31 pm

    Hello,

    Just and require_once(’Java.inc’); in you’re script.

    You’ll find this file in the source directory of php_java_bridge.

    regards

    david

    Post ReplyPost Reply
  • Trackback: developercast.com » Vinu Thomas’ Blog: Installing the PHP Java Bridge in Ubuntu (Gutsy Gibbon) Trackbacks
  • Trackback: Vinu Thomas’ Blog: Installing the PHP Java Bridge in Ubuntu (Gutsy Gibbon) | MT-Soft Website Development Trackbacks
  • Trackback: Installer PHP Java Bridge sur Ubuntu Trackbacks
  • Leave a Comment