Maison >développement back-end >tutoriel php >PHP/Java Bridge 实例 | PHP 调用 Java 实例
<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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了PHP/Java Bridge 实例 | PHP 调用 Java 实例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。