PHP/Java Bridge 构造方法传参

齐鸿光
2023-12-01
package test;

public class HelloWorld {
    public HelloWorld(String args){
        System.out.println(args);
    }

    public HelloWorld(int args,int args2){
        System.out.println(args);
        System.out.println(args2);
    }

    public static final String JAVABRIDGE_PORT = "28080";//这个8080端口是Java.inc里指定的
    static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner
            .getInstance(JAVABRIDGE_PORT);

    public static void main(String args[]) throws Exception {
        runner.waitFor();
    }

    public void hello(String args[]) throws Exception {
        System.out.println("!!!" + args[0]);
    }
}
<?php require_once("/home/gt/workspace/JavaPhp/Java.inc");
#require_once("http://localhost:8080/Java.inc");#这个http的方式报错,浏览器上可以访问的前提下

$str = new java("java.lang.String","abc");
$world0 = new java("test.HelloWorld",$str);
$world = new java("test.HelloWorld",111,222);#包名不写不行
echo $world->hello(array("from PHP"));
?>
 类似资料: