如何将 javac 的输出重定向回调用程序

发布于 2024-08-21 05:37:51 字数 625 浏览 11 评论 0原文

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-08-28 05:37:51

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文