<code><span>package</span> test; <span>public</span><span><span>class</span><span>HelloWorld</span> {</span><span>public</span><span>static</span><span>final</span> String JAVABRIDGE_PORT = <span>"8080"</span>;<span>//这个8080端口是Java.inc里指定的</span><span>static</span><span>final</span> php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner .getInstance(JAVABRIDGE_PORT); <span>public</span><span>static</span><span>void</span><span>main</span>(String args[]) <span>throws</span> Exception { runner.waitFor(); System.exit(<span>0</span>); } <span>public</span><span>void</span><span>hello</span>(String args[]) <span>throws</span> Exception { System.out.println(<span>"!!!"</span> + args[<span>0</span>]); } } </code>
<code><span><span><?php</span><span>require_once</span>(<span>"C:\Users\Administrator\workspace\JavaPhp\Java.inc"</span>); <span>#require_once("http://localhost:8080/Java.inc");#这个http的方式报错,浏览器上可以访问的前提下</span><span>$world</span> = <span>new</span> java(<span>"test.HelloWorld"</span>);<span>#包名不写不行</span><span>echo</span><span>$world</span>->hello(<span>array</span>(<span>"from PHP"</span>)); <span>?></span></span></span></code>
위 내용은 PHP/Java Bridge 예제 | PHP 호출 Java 예제를 포함하여 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.