I am trying to compile java files from a java program using org.apache.tools.ant.taskdefs.Javac and to print its output on screen.
See the below code snippet for your reference,
Javac javaCompile = (Javac) webServiceProject.createTask("javac");
javaCompile.setSrcdir("D:\\Java\\src");
javaCompile.setDestdir("D:\\Java\\classes");
try{
javaCompile.execute();
}catch (BuildException buildException){
FacesMessage message = new FacesMessage(buildException.getMessage());
message.setSeverity(FacesMessage.SEVERITY_FATAL);
FacesContext.getCurrentInstance().addMessage(null, message);
}
When i compile the files with the above code and if any compilation error exists, i get a message "Compile failed; see the compiler error output for details.".
I don’t know how to retrieve the compilation error and show it as an output on screen.
Can anyone suggest how to retrieve it?
The below code did the trick and this retrieved me the compiler error.