Home  >  Article  >  Backend Development  >  PHP/Java Bridge instance | PHP calls Java instance

PHP/Java Bridge instance | PHP calls Java instance

WBOY
WBOYOriginal
2016-07-29 09:01:011016browse

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); }); });

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn