javac:Solaris中找不到文件

时间:2012-06-28 06:23:47

标签: java solaris javac

我想运行javac来编译Solaris区域中的muiltiple文件,我可以手动完成,但下面的代码不能正常工作:

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个完整文件路径的串联)=

  

“/选择/ glassfish3 /的glassfish /域/域1 /温度/ 1b504235dc6be0558532a7b7bf27 /方法/ 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   /opt/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 /”(存在)在运行时之前),它仍然失败,但是如果我手动进入该目录并且只需输入具有完整15个文件路径名的javac就可以了。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的,所以我弄清楚我犯了什么简单的错误 - 而不是将多个文件路径连接到'allfiles'并将其作为单个参数传递我需要将每个文件路径作为自己的参数传递给ProcessBuilder,或者传递所有参数都是一个数组。