问题
I try to run an jar from an php file like this:
exec("java -jar /home/florinbuda/NetBeansProjects/monkey1/dist/monkey1.jar", $result);
print_r($result);
and IT WORKS if I run it from command line like:
$ php runner.php
but it doesn't work if I try to load it via http-localhost-server/runner.php the page just keeps loading forever without giving any error..
In the .jar file I added a simple test to now if the jar is even started to work
public static void main(String[] args) {
new File("/home/florinbuda/Desktop/xxx").mkdir();
and as you can guess - when I call http-localhost-server/runner.php the jar is not even started to be executed...
It's a problem of rights? What suggestions do you have?
回答1:
Yes, it's the problem of permission.
You should chmod the parent folder of .jar file.
chmod 755 -R /home/florinbuda/NetBeansProjects/monkey1/dist/
EDIT: And then your script should look like this:
exec("PATH_TO/java -jar /home/florinbuda/NetBeansProjects/monkey1/dist/monkey1.jar");
回答2:
The environment variables in bash aren't the same in exec(). Use the full path for java bin at least. You could also try just to run /path/to/java to see the normal output is working.
来源:https://stackoverflow.com/questions/13368155/why-execjava-jar-file-jar-dont-work-on-browser-but-works-on-command-line