I want to run javac to compile muiltiple files in a Solaris zone and I can do it manually but my code below isn't working:
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());
}
In the ProcessBuilder creation
dirJava = "/usr/jdk/instances/jdk1.6.0/bin/javac"
dir = "/opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/"
allfiles (a concatenation of 15 full file paths below) =
"/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 /opt/glassfish3/glassfish/domains/domain1/temp/1b504235dc6be0558532a7b7bf27/methods/String_Distance/u/DistanceInstance.java"
The process errors with javac: file not found: /opt/glassfish3/glassfish/domains/...' (the error lists all 15 files' full paths here)
But if I go into the 'dir' directory in the command prompt and type 'javac' with a space then the full 15 file paths from the file not found error message (copied verbatim) the command works and generates .class files for all those files in the same directory as the .java files. (I've checked there are no leading or trailing spaces in the allfiles and dir variables in my code).
I thought maybe it's because the last directory in 'dir' is created at run-time based on a sessionId so I tried 'dir' = "/opt/glassfish3/glassfish/domains/domain1/temp/" (which exists before run-time), and it still fails, but again if I manually go into that directory and simply type javac with the full 15 file pathnames it works. Any ideas?