在PHP中执行Java类 [英] Execute java class in PHP

查看:38
本文介绍了在PHP中执行Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用一个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)

http://sourceforge.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_6.2.1/php-java-bridge_6.2.1_documentation.zip/download

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆