如何使用传递给main方法的参数从php调用可执行jar
问题描述:
我创建了一个可执行jar,它工作正常。出于测试目的,我在main方法中使用了一个虚拟变量。
I have created an executable jar and it works fine. For the testing purpose, I have used a dummy variable in the main method.
相反,我需要传递一个字符串变量,同时从php调用这个可执行jar。
Instead, I need to pass a string variable, while calling this executable jar from php.
简而言之,我需要:
- 从PHP调用可执行jar
- 在调用jar时,我需要将PHP中的字符串变量传递给可执行jar内的类的main方法。
我如何完成上述规定?
How can I accomplish the aforesaid?
答
shell_exec("java -jar your_JAR.jar arg1 arg2");
你也可以使用 exec 而不是 shell_execute
,给它 $ output
和& $ return_var
变量(参见链接的手册页),并在通话后查看它们包含的内容。
you can also execute Java at all by using exec instead of shell_execute
, giving it $output
and & $return_var
variables (see the linked manual page) and seeing what they contain after the call.