1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public static void compile(File src, File bin)
{
try
{
final File[] inSrc = src.listFiles();
String cmd = " -d \"" + bin + "\"";
for (File f : src.listFiles())
cmd += " \"" + src.getCanonicalPath() + "\\" + f.getName() + "\"";
cmd = "java -cp tools.jar com.sun.tools.javac.Main " + cmd;
runProcess(cmd);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static void printLines(String name, InputStream ins, PrintStream out) throws Exception
{
String line = null;
BufferedReader in = new BufferedReader(new InputStreamReader(ins));
while ((line = in.readLine()) != null)
{
out.println(name + " " + line);
}
}
private static void runProcess(String command) throws Exception
{
Process pro = Runtime.getRuntime().exec(command);
printLines(command + " stdout:", pro.getInputStream(), System.out);
printLines(command + " stderr:", pro.getErrorStream(), System.err);
pro.waitFor();
System.out.println(command + " exitValue() " + pro.exitValue());
} |