Java calls the ant's custom task,
File BuildFile = new File (".//ee-build.xml");
Create an ant project
Project P = new Project ();
Create a default listener to listen for log operations during project build
Defaultlogger Consolelogger = new Defaultlogger ();
Consolelogger.seterrorprintstream (System.err);
Consolelogger.setoutputprintstream (System.out);
Consolelogger.setmessageoutputlevel (Project.msg_info);
P.addbuildlistener (Consolelogger);
try {
P.firebuildstarted ();
Initialize the project
P.init ();
Projecthelper helper = Projecthelper.getprojecthelper ();
Parse the project's build file
Helper.parse (P, buildfile);
Perform one of the objectives of a project
P.executetarget ("Hello");
P.firebuildfinished (NULL);
} catch (Buildexception be) {
P.firebuildfinished (BE);
}
}
If the target in the Java call uses Antcall to invoke another target, and the target is not defined in Build.xml, the target cannot be found. Because although the file specified above is ee-build.xml, Ant will find the target from Build.xml by default.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java calls Ant's custom task, which is not a build.xml problem by default