改为:
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 <b>".$myjava->test("hello java, i m php.")."</b><br>/n";
$myjava->teststring = "java, i gave you a string.";
echo "you have set string is: <b>".$myjava->teststring."</b><br>/n";
echo "my java method reports:<b>".$myjava->getteststring ()."</b><br>/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.
新闻热点
疑难解答