Tuesday, June 09, 2009

Unzip Using Ant Code


package com.test.ant;

import java.io.File;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;

public class AntUnzip {

public static void main(String[] args) {
File src = new File("1.zip"); // Source Zip File Name
File dest = new File("test"); // Destination Folder Name
Expand expand = new Expand();
expand.setSrc(src);
expand.setDest(dest);
callAntTask(expand, "Unzip");
}

public static void callAntTask(Task task, String taskName) {
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_DEBUG);
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
Project project = new Project();
project.addBuildListener(logger);
task.setProject(project);
task.setTaskName(taskName);
task.execute();
}

}

No comments: