How can I redirect output from javac back to 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 the xterm window, calls javac on the panel panel_1.java, it compiles if the panel_1.java file is valid. then the xterm window closes. Great, I want to accept warnings, etc. From compilation and put them in a list or text. Any ideas ???

+3
source share
1 answer

Java 6 comes JavaCompilerfrom a package javax.toolsthat provides an API to the compiler without having to start an external process, (read the javadoc I'm connected with!)

Here is a short tutorial on this.

+5
source

Source: https://habr.com/ru/post/1732710/


All Articles