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 '));