我尝试使用 Runtime.getRuntime.exec(command) 编译一些 java 文件并生成命令。下面的代码显示了我在做什么:
String command = "javac ";
for(String s: this.getPackages())
{
command = command + "/home/benuni/CompileFiles/" + project + "/" + s + "/*.java ";
}
try {
System.out.println("command: '"+ command +"'");
Process pro = Runtime.getRuntime().exec(command);
printLines(" stderr:", pro.getErrorStream());
pro.waitFor();
这给出了以下输出:
command: 'javac /home/benuni/CompileFiles/HelloWorldProject/HelloWorldPackage/*.java '
stderr: javac: file not found: /home/benuni/CompileFiles/HelloWorldProject/HelloWorldPackage/*.java
stderr: Usage: javac <options> <source files>
stderr: use -help for a list of possible options
它不工作..但是如果我将命令复制到我的shell中,它就没有问题......有什么想法吗?