如何创建Java类对象并在PHP中运行其功能?

如何创建Java类对象并在PHP中运行其功能?

问题描述:

I have two files, index.php and foo.java. In foo.java I have the class bar with the function foobar.

Now I want to create object baz in my index.php of the class bar and make it run function foobar. I know PHP and Java don't speak the same language, but I can use JSON to create an java object and have it call the function? If so, how?

我有两个文件,index.php和foo.java。 在foo.java中,我有一个带有foobar函数的类栏。 p>

现在我想在类栏的index.php中创建对象baz并使其运行foobar函数。 我知道PHP和Java不会说同一种语言,但我可以使用JSON创建一个java对象并让它调用该函数? 如果是这样,怎么样? p> div>

You can use shell_exec and run java from CLI.

<?php
$output = shell_exec('java [MyPackage.]MyClass MY_METHOD');
echo "<pre>$output</pre>";
?>