import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
健壮性是Ant的最大优势。Ant任务可以掩盖错误并提供良好的边界条件。 Ant任务在各种上下文中使用,并且能够处理异常和控制流。
跨平台是另一个优势,它允许在所有平台上执行,无论是UNIX,Windows还是MacOS。
Ant的社区使我们能够与开放世界分享和理解。整个Apache Ant社区都支持Ant代码。
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.taskdefs.Expand;
import java.io.File;
public class JavaTaskExample{
public static void main(String[] args){
unzip(zipFilepath, destinationDir);
}
static public void unzip(String zipFilepath, String destinationDir) {
try{
final class Expander extends Expand {
public Expander() {
project = new Project();
project.init();
taskType = "unzip";
taskName = "unzip";
target = new Target();
}
}
Expander expander = new Expander();
expander.setSrc(new File(zipfile));
expander.setDest(new File(destdir));
expander.execute();
}
}catch(BuildException e){
System.out.println(e);
}
}