java 如何使用传递给main方法的参数从php调用可执行jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16766464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call an executable jar from php with an argument passed to main method
提问by user264953
I have created an executable jar and it works fine. For the testing purpose, I have used a dummy variable in the main method.
我创建了一个可执行的 jar,它工作正常。出于测试目的,我在 main 方法中使用了一个虚拟变量。
Instead, I need to pass a string variable, while calling this executable jar from php.
相反,我需要传递一个字符串变量,同时从 php 调用这个可执行的 jar。
In short, I need to:
简而言之,我需要:
- Call the executable jar from PHP
- While calling the jar, I need to pass a string variable from PHP to the main method of the class inside executable jar.
- 从 PHP 调用可执行 jar
- 在调用 jar 时,我需要将一个字符串变量从 PHP 传递到可执行 jar 中的类的 main 方法。
How can I accomplish the aforesaid?
我怎样才能完成上述操作?
回答by Sumit Singh
shell_exec("java -jar your_JAR.jar arg1 arg2");
you can also execute Java at all by using execinstead of shell_execute
, giving it $output
and & $return_var
variables (see the linked manual page) and seeing what they contain after the call.
您还可以通过使用exec而不是shell_execute
,给它$output
和 &$return_var
变量(参见链接的手册页)并在调用后查看它们包含的内容来完全执行 Java 。