Sunday, March 13, 2011

install and configure Zend server Java Bridge on Linux

As far as I know, there are two active PHP-Java bridge projects. One is PHP/Java Bridge hosted on SourceForge. The other is Java bridge coming with Zend Server and Zend Server CE for linux and IBM i. It is clear that sourceForge PHP/Java bridge is based on SOAP web service. But, this make me feel it is not useful so much as it is not difficult for a PHP programmer to write SOAP client to call a SOAP service written in Java. I guess Zend Java bridge is implemented in client/server architecture too as its configuration parameters include a TCP/IP port number. I thought Zend Java Bridge is written based on JNI technology. However, it seems not true.

Anyway, the mystification of Zend Java Bridge attracts me to give it a shot. Here are simple steps about how to install and configure Zend Java Bridge.

1) Following post Installing Zend server CE on Fedora 14 and fix YUM update to install Zend Server CE on Fedora 14.

2) Running command yum search java-bridge to have output similar as below.

[root@jiaFedora14 yyjia]# yum search java-bridge
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
updates/pkgtags | 56 kB 00:00
======================================================================== Matched: java-bridge =========================================================================
php-5.2-java-bridge-zend-server.x86_64 : Zend Java bridge
php-5.3-java-bridge-zend-server.x86_64 : Zend Java bridge
[root@jiaFedora14 yyjia]#


3) call command yum install php-5.3-java-bridge-zend-server to install Zend Java Bridge as I installed php 5.3 version on my machine.

4) call command /usr/local/zend/etc/rc.d/06jb stop and command /usr/local/zend/etc/rc.d/06jb start to start Zend Java Bridge if it is necessary. Or you can enable/disable Zend Java Bridge from Zend Server admin Web page.

5) compile following Java code into a .jar file, say jia.jar and add put it into directory /usr/local/zend/bin.

SystemPropertyList.java
package jia.blog.util.lang;

import java.util.Properties;

/**
 *
 * @author Yiyu Jia
 */
public class SystemPropertyList {

    public static Properties listSystemProperties(){
         return System.getProperties();
    }
}


6) open file /usr/local/zend/etc/watchdog-jb.ini and add jia.jar file into the CLASSPATH.

7) put below PHP code into directory, where Zend server executes php file. For example, /var/www/html.

javaInfo.php
<?php
$javaEnv = new Java("jia.blog.util.lang.SystemPropertyList");
$out = $javaEnv->listSystemProperties();
?>

List of JVM System Properties

<?php foreach($out as $key => $value) { ?> <?php } ?>
<?php echo $key; ?> <?php echo $value; ?>

8) open web browser and access php code, for example http://localhost/javaEnv.php. If you can see the list of Java system properties, it is done. Enjoy it. This Java system properties is very important for Java programmer to create java app running in Zend Java Bridge.

Note: it seems that Zend Java Bridge does not support Java class hot deployment. So, you may need to restart Java Bridge every time after you modified your java classes.

7 comments:

  1. you saved my life! thanks!

    ReplyDelete
  2. Hi Jia,

    Where should we keep the *.properties file for language translation (its for jasper report integration) ,Where to make bundle folder in java bridge corresponding to WEB-INF/Bundles in java

    ReplyDelete
  3. Interesting question. But, I am confused that you ask this question here. Wont you install your Jasper with application server like Tomcat?

    ReplyDelete
  4. hi Jia
    thanks a lot for your tuto
    but a have always the same problem

    i try a lot of thinks but nothing work

    error
    No Class!*->jbridge('med.util.lang.S...')
    any idea thanks

    ReplyDelete
  5. Where is med.util.lang.S from? I feel you need to double check the Step 5 and Step 6. Did you put your third party libraries under folder /usr/local/zend/bin ?

    ReplyDelete
  6. Thank you for this invaluable information. I have a problem in trying Java Bridge: while I managed to install it perfectly fine locally, I cannot manage to have it running on an Openshift cloud. The problem is, I am not allowed to access packages in /var/lib/rpm. Openshift allows users to install packages ("cartridges") and I got Zend, but Java Bridge is not available by default. Do you know if it is possible to donwload the Zend Java Bridge package individually somewhere? My access restrictions on OpenShift are strange, e.g. I managed to install Jython from the .jar installer without any problem. Thank you!

    ReplyDelete
    Replies
    1. I did not try to install them remotely. But, I would check the 06jb and chase all related jar files and configuration file.

      Also, did you try http://php-java-bridge.sourceforge.net/pjb/ ?

      Delete