简体   繁体   English

如何使用传递给main方法的参数从php调用可执行jar

[英]How to call an executable jar from php with an argument passed to main method

I have created an executable jar and it works fine.我创建了一个可执行的 jar,它工作正常。 For the testing purpose, I have used a dummy variable in the main method.出于测试目的,我在 main 方法中使用了一个虚拟变量。

Instead, I need to pass a string variable, while calling this executable jar from php.相反,我需要传递一个字符串变量,同时从 php 调用这个可执行的 jar。

In short, I need to:简而言之,我需要:

  1. Call the executable jar from PHP从 PHP 调用可执行 jar
  2. While calling the jar, I need to pass a string variable from PHP to the main method of the class inside executable jar.在调用 jar 时,我需要将一个字符串变量从 PHP 传递到可执行 jar 内的类的 main 方法。

How can I accomplish the aforesaid?我怎样才能完成上述操作?

shell_exec("java -jar your_JAR.jar arg1 arg2");

您还可以通过使用exec而不是shell_execute来执行 Java,为它提供$output和 & $return_var变量(请参阅链接的手册页)并在调用后查看它们包含的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM