I want to connect to java via php and print the result out in php. Now I want to send a parameter to java and return it to php to see how it works. How can I do this?
I have this code so far:
PHP:
exec("java jar/name.jar", $output);
print_r($output);
Java:
public class Main {
public static void main(String[] args) {
System.out.print(args[0]);
}
}
The result is
Array ( )
解决方案
Do
exec("/full/path/to/java -jar jar/name.jar 2>&1", $output);
print_r($output);
because
your PHP env probably doesn't have java executable defined in the path (and it shouldn't, either)
jar files are executed with java -jar
you'll want 2>&1 to be able to see error messages in the output (redirect from stderr to stdout)