1,ant脚本调用java程序
a,建立一个java类,继承ant的Task类:
package org.example;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class ExampleTask extends Task {
private String msg;
// The method executing the task
public void execute() throws BuildException {
System.out.println(msg);
}
// The setter for the "message" attribute
public void setMessage(String msg) {
this.msg = msg;
}
}
b,ant脚本:
c,运行ant脚本。
2,java程序调用ant脚本
1,建立一个java类,
package org.example;
import java.io.File;
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 AntExample {
/**
* @param args
*/
public static void main(String[] args) {
File buildFile = new File("example.xml");
Project p = new Project();
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
}
}
b,ant脚本:
c,运行java程序。