package org.apache.easframework.common;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
public class CompileJava {
public static synchronized boolean compile(String buildFilePath, String logFilePath) {
File buildFile = new File(buildFilePath);
Project project = new Project();
DefaultLogger consoleLogger = new DefaultLogger();
try {
FileOutputStream fs = new FileOutputStream(logFilePath);
PrintStream ps = new PrintStream(fs);
consoleLogger.setErrorPrintStream(ps);
consoleLogger.setOutputPrintStream(ps);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener(consoleLogger);
try {
project.fireBuildStarted();
project.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
helper.parse(project, buildFile);
System.out.println("默认target:");
System.out.println(project.getDefaultTarget()); //默认的target是help
project.executeTarget("all"); //调用的task是all
project.fireBuildFinished(null);
return true;
} catch (BuildException e) {
project.fireBuildFinished(e);
return false;
}
}
public static String startCompile(String buildFile,String logFile)
{
if(CompileJava.compile(buildFile, logFile))
{
return "编译成功!";
}
else
{
return "编译失败!";
}
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("开始编译...");
boolean b = CompileJava.compile("D:/easdev/build/userbuild.xml",
"D:/easdev/build/userbuild.log");
if(b)
{
System.out.println("编译成功!");
}
else
{
System.out.println("编译失败!");
}
System.out.println("结束编译...");
}
}
ANT CompileJava
最新推荐文章于 2024-05-22 10:08:59 发布
本文提供了一个使用Apache Ant工具进行Java编译的示例代码。该代码通过配置Ant任务来实现Java项目的编译过程,并将编译日志输出到指定文件中。如果编译成功,则返回编译成功的消息;若失败则返回编译失败。此示例展示了如何利用Ant的灵活性和强大的构建功能。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1196

被折叠的 条评论
为什么被折叠?



