Php/java Bridge uses

Source: Internet
Author: User

Php/java Bridge, like its name, is the use of PHP invoke Java code, the general situation of the PHP project is not used, but sometimes, some drivers or interfaces only support Java time, and happens to our project is PHP
, it needs to be used. If you don't say more, here's a direct introduction to the steps to use, and here's a Windows environment example:

First, to ensure that there is PHP and Java operating environment, this is not much said, and then download Javabridge.jar. Double-click to open directly:

It will brake the selection of unused ports, this is the local 8081 port.


Second, write the Java class you want to invoke:

public class Test {public
    String getString () {return
        ' php get Java ';
    }

    public string setstring (String str) {
        return  ' Your input is ' +str
    }
}
A very simple test class is written here.


Third, the Java class into a jar package, I use the IntelliJ idea, here describes how to pack:

Build-> build artifacts and then action, select Build.

OK, and then your jar bag will hit the Out\artifacts\ project name _jar.


Put your jar bag where Java can call, I put it under Jre\lib\ext.

Set allow_url_include = On in php.ini.

Write PHP code invoke Java class:

	Require_once ("Http://localhost:8081/JavaBridge/java/Java.inc");
	$test =new java ("test");
	$res = Java_values ($test->getstring ());
	$res 1 = java_values ($test->setstring (' Yukari '));


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.