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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100