header("content-type:text/html; charset=utf-8");
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
$s = new Java("java.lang.String", "php-java-bridge config...<br><br>");
echo $s;
Java version=1.6.0_10
Java vendor=Sun Microsystems Inc.
OS=Windows Vista 6.0 on x86
星期日, 十一月 23, 2008 at 4:31:49 下午 中国标准时间
-------自定义JAR
package ttt;
public class phptest{
/**
* A sample of a class that can work with PHP
* NB: The whole class must be public to work,
* and of course the methods you wish to call
* directly.
*
* Also note that from PHP the main method
* will not be called
*/
public String foo;
/**
* Takes a string and returns the result
* or a msg saying your string was empty
*/
public String test(String str) {
if(str.equals("")) {
str = "Your string was empty. ";
}
return str;
}
/**
* whatisfoo() simply returns the value of the variable foo.
*/
public String whatisfoo() {
return "foo is " + foo;
}
/**
* This is called if phptest is run from the command line with
* something like
* java phptest
* or
* java phptest hello there
*/
public static void main(String args[]) {
phptest p = new phptest();
if(args.length == 0) {
String arg = "";
System.out.println(p.test(arg));
}else{
for (int i = 0; i < args.length; i++) {
String arg = args;
System.out.println(p.test(arg));
}
}
}
}
public class phptest{
/**
* A sample of a class that can work with PHP
* NB: The whole class must be public to work,
* and of course the methods you wish to call
* directly.
*
* Also note that from PHP the main method
* will not be called
*/
public String foo;
/**
* Takes a string and returns the result
* or a msg saying your string was empty
*/
public String test(String str) {
if(str.equals("")) {
str = "Your string was empty. ";
}
return str;
}
/**
* whatisfoo() simply returns the value of the variable foo.
*/
public String whatisfoo() {
return "foo is " + foo;
}
/**
* This is called if phptest is run from the command line with
* something like
* java phptest
* or
* java phptest hello there
*/
public static void main(String args[]) {
phptest p = new phptest();
if(args.length == 0) {
String arg = "";
System.out.println(p.test(arg));
}else{
for (int i = 0; i < args.length; i++) {
String arg = args;
System.out.println(p.test(arg));
}
}
}
}
创建这个文件后,我们要编译好这个文件,在 DOS 命令行使用 javac phptest.java 这个命令。