改為:
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.
新聞熱點
疑難解答