如何将 javac 的输出重定向回调用程序
// 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 窗口关闭。很好,我想从编译中获取警告等,并将它们放入列表或文本区域中。 有什么想法吗???
// 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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java 6 有
JavaCompiler
< /a> 来自javax.tools
包,它为编译器提供 API,无需运行外部进程。 (阅读我链接的javadoc!)这里还有一个关于这个问题的小教程。
Java 6 has
JavaCompiler
from thejavax.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.