The latest use of the PHP JAVA Bridge Bridge

Source: Internet
Author: User

Build a bridge between PHP and Java and use this bridge to build a communication channel between the two entities, with the help of this bridge, you can develop classes in Java , and then in PHP In the same way that you can use PHP scripts in your Java desktop or Web application.

http://php-java-bridge.sourceforge.net/pjb/ is the official website for PHP Java Bridge . You can view the details of PHP JAVA Bridge on this website.

Installation and Configuration Php/java Bridge

The latest Php/java bridge Zip package is available at http://sourceforge.net/projects/php-java-bridge/files/ Download Javabridgetemplate611.war, this package size is 523KB the installation process relies on choosing which Java platform to interact with the PHP script through this bridge. Here are the environments and versions required to install Java and php .

Install J2SE 1.6 or later

Configure the Java environment variable (this is very simple I will not say more)

Install PHP 5.2.6 or later

Modify the configuration in the php.ini file to:

  Allow_url_fopen =  on = on

Restart Apache.

Install java_ee_sdk-6.

Copy the downloaded Javabridgetemplate611.war package ( the file name of this package can be modified ) directly to the java_ee_sdk-6 C:\glassfishv3\glassfish\domains\domain1\autodeploy of the installation directory.

then put the compiled Java class file jar package into the Javabridgetemplate611.war in the lib directory (with Javabridge.jar package in the same directory). Restart the Java EE 6 SDk.

This allows the Java method to be called in a PHP file.

Here is a test class of Java that I wrote, with the file name Test.java:

 Public classTest { PublicString name = "";  Public voidSetName (String name) { This. Name =name;}  PublicString getname () {return  This. Name;  Public floatAddfloatNUM1,floatnum2) {  returnNUM1 +num2;}} 

The Test.java file into a Test.jar package, and then placed in the Javabridgetemplate611.war in the Lib directory (with the Javabridge.jar package in the same directory). Restart the Java EE 6 SDk.

The following is a test file for PHP test.php

<?PHPHeader(' content-type:text/html; Charset=utf-8 ');require_once("Http://localhost:8080/JavaBridgeTemplate611/java/Java.inc");//get instance of Java class Java.lang.System in PHP$system=NewJava (' Java.lang.System ');//Demonstrate property accessEcho' Java version= '.$system->getproperty (' java.version '). ' <br/> ';Echo' Java vendor= '.$system->getproperty (' Java.vendor '). ' <br/> ';Echo' os= '.$system->getproperty (' Os.name '). ‘ ‘ .$system->getproperty (' os.version '). ' On '.$system->getproperty (' Os.arch '). ' <br/> ';//Java.util.Date Example$formatter=NewJava (' Java.text.SimpleDateFormat ', "eeee, MMMM dd, yyyy ' at ' H:mm:ss a zzzz");Echo $formatter->format (NewJava (' Java.util.Date '));Echo' <br/> ';//Here's how PHP calls itself to write Test.java.         $test=NewJava ("Test");//The generated instance "test" is the Java Jar package name.         $test->setname ("PHP calls Java Method! ");//The subsequent call is just like calling the class method in PHP                Echo"Call the GetName method of class test, the return value is:------------".$test->getname (). " <br> "; Echo"Call Test's Add method with the return value:--------".$test->add (11.9, 15.2);?>

Then run the test.php file if you get the following result, which indicates the configuration and the call succeeded.

Java VERSION=1.6.0_10-RC2
Java Vendor=sun Microsystems Inc.
Os=windows XP 5.1 on x86
Tuesday, April at 4:57:59 China Standard Time
Call the GetName method of class test, the return value is:------------php call Java Method!
Call the Add method of test, and the return value is:--------27.099998

The latest use of the PHP JAVA Bridge Bridge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.