开发者社区> 问答> 正文

无法执行PHP中的Java文件?

我正在使用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");

?>

这两个文件都位于同一目录中,我在这里丢失了...。

展开
收起
社区秘书 2019-12-09 15:23:55 715 0
1 条回答
写回答
取消 提交回答
  • 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.

    2021-02-06 20:44:54
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载