时间:2021-07-01 10:21:17 帮助过:4人阅读
改为:
java.class.path = "JAVA的CLASS_PATH;(将要放置自己的class文件的目录)d:\java_for_php"
java.home = "JAVA的JAVAHOME"
java.library = "JAVA的JAVAHOME\jre\bin\server\jvm.dll"
java.library.path = "PHP安装目录\extensions\"
修改好后,php.ini 文件必须放在Windows安装目录内,重新启动Apache。
在d:\java_for_php内新建一个PhpCallJava.java ,内容如下:
public class PhpCallJava {
public String testString;
public String test (String str) {
if (str.equals("")) {
return "This is a empty string!";
} else {
return str;
}
}
public String GetTestString () {
return "Your string is: " testString;
}
}
编译PhpCallJava.java 生成PhpCallJava.class
新建一个PHP文件,内容如下:
php
$myjava = new Java("PhpCallJava");
echo "Test Result are ".$myjava->test("Hello JAVA, I m PHP.")."
\n";
$myjava->testString = "JAVA, I gave you a string.";
echo "You have set string is: ".$myjava->testString."
\n";
echo "My java method reports:".$myjava->GetTestString ()."
\n";
?>
结果:
Test Result are Hello JAVA, I m PHP.
You have set string is: JAVA, I gave you a string.
My java method reports:Your string is: JAVA, I gave you a string.