// 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();
}
}
这将打开一个xterm窗口,在panel_1.java上调用javac,如果panel_1.java是有效文件,它将进行编译.然后xterm窗口关闭.好吧,我想从编译器中获取警告等信息,并将其放入列表或textArea中.
有任何想法吗???
解决方法:
Java 6从javax.tools包中获得了JavaCompiler
,它为编译器提供了API,而无需运行外部进程. (阅读我链接的javadoc!)
Here也是有关此问题的一些小教程.