dsbo44836129 2014-09-29 20:29
浏览 157
已采纳

无法从php exec方法执行java类文件?

I am trying to execute a java class file from php using the exec method. However, i get the following error.

I have set chmod 777 to the java class file so i suppose permission is not an issue.

For some reason it is not able to find it ?

I can run the java class file from the terminal using the java command without any problem

Error:

Error: Could not find or load main class .var.www.redbutton.readBashScript.class


<?php

exec('java /var/www/redbutton/readBashScript.class');

?>

and

<?php

exec('java /var/www/redbutton/readBashScript');

?>
  • 写回答

1条回答 默认 最新

  • douxi3977 2014-09-29 20:32
    关注

    The java exec does not work like that.

    You need not pass the file to "execute", but the class which is why you get an error.

    You must do:

    java -cp /var/www/redbutton readBashScript
    

    But:

    • /var/www/redbutton must be a classpath directory, where your .class reside. Java will by default try to find classes in the current directory, which explains why it work in the console.
    • readBashScript must be the name of a class containing a main method.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?