开发者

how can I redirect output from javac back into the calling program

开发者 https://www.devze.com 2022-12-19 22:45 出处:网络
// this works if (\"Show\".equals (obj)) { try { String command= \"/usr/bin/xterm -ejavacpanel_1.java\";
// 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号