<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>
The above introduces the PHP/Java Bridge example | PHP calls Java example, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.