[英]Ant Javac Compilation Output
我正在尝试使用org.apache.tools.ant.taskdefs.Javac
从Java程序编译Java文件,并在屏幕上打印其输出。
请参阅以下代码段供您参考,
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);
}
当我使用上述代码编译文件时,如果存在任何编译错误,则会收到消息"Compile failed; see the compiler error output for details."
。
我不知道如何检索编译错误并将其显示为屏幕上的输出。 谁能建议如何找回它?
下面的代码可以解决问题,这使我检索到编译器错误。
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);
忽略是否应该在JSF应用程序中编译代码的问题...
我相信Ant会将编译输出发送到记录器。 因此,要掌握它,您将需要配置记录器,以将相关的日志事件发送到文件……等等。
尝试更改build.compiler设置。 Ant在查找我指定的编译器“ org.eclipse.jdt.core.JDTCompilerAdapter”时遇到了麻烦-将其更改为“现代”可以进行编译。
很难追踪。 我不确定为什么没有输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.