我正在使用shell_exec命令在php中执行Java文件,但未按预期获得类文件
Main.java
public static void main(String[] args) {
String [] data = {"abc","xyz"};
for (int i = 0; i < data.length; i++) {
System.out.println(data[i]);
}
}
}
test.php
echo "Hello!!!!";
shell_exec("javac Main.java");
// echo shell_exec("java Main");
?>
这两个文件都位于同一目录中,我在这里丢失了...。
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 /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.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。