how can I redirect output from javac back into the calling program
// this works
if ("Show".equals (obj))
{
try {
String command= "/usr/bin/xterm -e javac panel_1.java";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
while (开发者_开发百科(line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
This opens an xterm window , calls javac on panel_1.java, it compiles if panel_1.java is a valid file. then the xterm window closes. Fine I want to take the warnings, etc., from the compile and put them in a list or a textArea. Any Ideas???
Java 6 has JavaCompiler
from the javax.tools
package which provides an API to the compiler without the need to run an external process. (read the javadoc I linked!)
Here is a little tutorial on the matter as well.
精彩评论