在PHP中执行Java类 [英] Execute java class in PHP
问题描述
我想调用一个Java程序并在stdout中获取它的输出.我遵循了它很容易安装且运行良好.
此外,我建议使用以下链接下载它.(与downloads-> documentation中的链接相同)
stackoverflow. But it doesn't work.
I have add the class file to my CLASSPATH. And I can execute the command in cmd correctly as follows:
In my PHP file I call this program by
exec("java Hello", $output);
print_r($output);
It yields nothing but:
Array()
What is the problem? How can I fix this?
ps: Hello is a demo program, actually the program I want to call is much more complicated which might take 2 or more seconds in my machine(i5 4G).
I would recommend using Java/PHP Bridge found here: http://php-java-bridge.sourceforge.net/pjb/ It's quite easy to install and works very well.
Also, I recommend using the following link to download it. (it's the same one as the link in downloads->documentation)
The file is JavaBridge.war. You'll probably want to use Tomcat for the Java EE container. Once Tomcat is set up, you just put this file in the webapps folder and it's installed.
If you want to regularly use java classes in PHP this is the best method I know of and I have tried a lot of them. Resin also worked, but it didn't play nice with my mail server.
这篇关于在PHP中执行Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!