1 有 execute()方法的类都可以
继承于Task可以使用ant的一些api
例子:
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class MVMergeTask extends Task {
//这个方法为ant 调用而写
public void execute() throws BuildException {
log("MVMergeTask 开始执行---------------");
List list = new ArrayList();
list.add("//file start ------------------");
try {
list.addAll(org.apache.commons.io.FileUtils.readLines(new File("f:/Receive.js")));
list.add("//file end --------------------");
org.apache.commons.io.FileUtils.writeLines(new File("f:/Receive3.js"), list);
} catch(Exception e) {
e.printStackTrace();
}
log("MVMergeTask 执行完毕---------------");
}
}
2 配置
<taskdef name="jsMerge"
classname="Freesky.M8.MM.Common.merge.MVMergeTask" classpath="WebContent/WEB-INF/lib/commons-io-1.4.jar;WebContent/WEB-INF/classes"/>
<target name="jsMergeTask" >
<jsMerge/>
</target>