Working with Java Bridge
The Java Bridge is only active when the Java Bridge component is installed and activated. The component's status and settings can be viewed and configured in the UI, on the Administration | Components page.
This procedure describes how to enable the Java Bridge component on IBMi.
To enable the Zend Java Bridge on IBMi:
|
This procedure describes how to install and enable the Java Bridge component depending on the Zend Server installation type.
Windows
Linux
aptitude install php-java-bridge-zend-server
|
This procedure describes how to configure the target Java runtime environment.
Configuring the runtime environment: Use the following command to run JavaMW: java com.zend.javamw.JavaServer For correct execution, the classpath should include the javamw.jar file in the directory where JavaMW is installed. |
|
Example: UNIX, Linux, and IBM i<install_dir>/bin/javamw.jar Windows <install_dir>\bin\javamw.jar |
The following code sample shows how you can, as an initial step, test the connection between your PHP and Java environments to ensure that the Java Bridge is defined properly and communicates with the correct Java. This code demonstrates the interaction between a PHP application and Java objects that occurs in the Java Bridge implementation.
To test the Java Bridge connection: Create a new PHP script to create a Java object, as in the example below: <?php// create Java object$formatter = new Java("java.text.SimpleDateFormat","EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");// Print date through the objectprint $formatter->format(new Java("java.util.Date"))."\n";// You can also access Java system classes$system = new Java("java.lang.System");print $system."\n"; // will use toString in PHP5print "Java version=".$system->getProperty("java.version")." <br>\n";print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";print "OS=".$system->getProperty("os.name")." ".$system->getProperty("os.version")." on ".$system->getProperty("os.arch")." <br>\n"; ?> If the Java Bridge is correctly installed and running, you should receive the following response: Friday, June 13, 2008 at 8:45:57 PM U.S Daylight Time class java.lang.System Java version=1.6.0_06 Java vendor=Sun Microsystems Inc.OS=Linux 2.6.25.3-18.fc9.i686 on i386 This output shows the date, Java version, vendor and operating
system and indicates that the connection is complete.
|
|
Once the connection is established, you can start using the API to call Java objects from your PHP. |
Before you start incorporating the Java Bridge API in your code, you
must be aware that when you call Java from PHP, you must use Java coding
standards to call the correct objects, because the Java Bridge does not
perform dynamic data conversion. You must perform the type conversion
in your PHP code.
For example,
|
Example: If you call a Java method that looks like this: public void doSomething(int i); Using what you would expect to work in PHP: $var = "1" $javaObject->doSomething($var); The Java Bridge throws an exception. To avoid this, use the following line of code to convert the parameter from a string to a numeric value before the Java Bridge passes it: $javaObject->doSomething($var + 0); |
For more information, see the API, or Java Bridge Use Cases.
This procedure describes how to configure the Zend Java Bridge component. For more information on working with this component, see Working with Components.
|
To configure the component:
|
For information on configuring the component daemon directives, see Configuring Component Daemon Directives (Zend Session Clustering, Zend Deployment, Zend Java Bridge, Zend Job Queue, and Zend Monitor). |