我想运行 javac 来编译 Solaris 区域中的多个文件,我可以手动完成,但下面的代码不起作用:
try {
File directory = new File(dir);
ProcessBuilder builder = new ProcessBuilder(dirJava, allfiles);
builder.directory(directory);
builder.redirectErrorStream(true);
Process process = builder.start();
InputStreamReader isr = new InputStreamReader(process.getInputStream());
BufferedReader br = new BufferedReader(isr);
String lineRead;
while ((lineRead = br.readLine()) != null) {
System.out.println("> "+lineRead);
}
process.waitFor();
}
catch (IOException e) {
System.out.println("Could not convert files: "+e.getMessage());
}
在 ProcessBuilder 创建中
dirJava = "/usr/jdk/instances/jdk1.6.0/bin/javac"
dir = "/opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/"
allfiles(以下 15 个完整文件路径的串联)=
"/opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/StringWrapper.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/DistanceInstanceIterator.java / opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/StringDistance.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/StringWrapperIterator.java /opt glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/Tokenizer.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/Jaccard。java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/BasicToken.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/BasicStringWrapper.java opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/StringDistanceLearner.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/DataTownMain.java /opt/ glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/BagOfTokens.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/Token。java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/SimpleTokenizer.java /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/AbstractStringDistance.java选择/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/DistanceInstance.java"
javac 的进程错误:找不到文件:/opt/glassfish3/glassfish/domains/...'(错误在此处列出了所有 15 个文件的完整路径)
但是,如果我进入命令提示符中的“dir”目录并键入带有空格的“javac”,则来自文件未找到错误消息(逐字复制)的完整 15 个文件路径该命令有效并为所有这些生成 .class 文件与 .java 文件位于同一目录中的文件。(我检查了代码中的 allfiles 和 dir 变量中没有前导或尾随空格)。
我想可能是因为 'dir' 中的最后一个目录是在运行时基于 sessionId 创建的,所以我尝试了 'dir' = "/opt/glassfish3/glassfish/domains/domain1/temp/" (在运行之前存在-时间),它仍然失败,但如果我再次手动进入该目录并简单地键入 javac 和完整的 15 个文件路径名,它就可以工作。有任何想法吗?