PHP Call from Java Using Quercus

巧了我就是萌 提交于 2020-01-01 19:24:12

问题


I have a sample PHP class which I would like to Utilize in my Java Application.

We have decided to use Quercus as a Libary for doing the Integration.

Can some one let me know How can I call a PHP class from Java Code using Quercus.

For Example.

PHP class name is calculator.php and it has one method say sum() which expects 2 numbers to be passed and It will do the summation of those number.

Please let me know the sample code which can be coded to achive the same.

Thanks,


回答1:


You should look at QuercusEngine

import com.caucho.quercus.QuercusEngine;

QuercusEngine engine = new QuercusEngine();
engine.setOutputStream(System.out);
engine.executeFile("src/test.php");

Other examples

The only needed jars are resin.jar and servlet-api.jar.




回答2:


It seems that you can't usefully instantiate a QuercusEngine these days. Instead:

import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;

QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();

You then probably want engine.eval(reader);



来源:https://stackoverflow.com/questions/5298123/php-call-from-java-using-quercus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!