开发者

Ant Javac Compilation Output

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 =开发者_StackOverflow (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?


Ignoring the issue of whether you should be compiling code in a JSF application ...

I believe that Ant sends compilation output to the logger. So to get hold of it, you will need to configure the logger to send the relevant log events to a file ... or something.


Try changing the build.compiler setting. Ant was having trouble finding the compiler I had specified, "org.eclipse.jdt.core.JDTCompilerAdapter" - changing it to "modern" allowed me to compile.

This was tricky to track down. I'm not sure why there was no output.


The below code did the trick and this retrieved me the compiler error.

Javac javaCompile = (Javac) webServiceProject.createTask("javac");
javaCompile.createCompilerArg().setValue("-Xstdout");
String filePath = basePath + "resources" + File.separator
        + "errorlog.log";
javaCompile.createCompilerArg().setFile(new File(filePath));
javaCompile.setNowarn(true);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜