Create your own ant task
Ant has an advantage on portability over many others solutions.
As Ant can call shell script, the ugly solution to most problem can be
solved by calling external script.
Well,at first this solution doesn't look so bad ! However, very often,
this solution is not portable.
Ant is based on Java, hence you have the ability to write non dependent building application mechanism.
Here is an example :
<project name="antTest" default="default" basedir="."> <target name="my-fisrt-own-task" depends="compile"> <taskdef name="mytask" classname="MyTask" classpath="${build.dir}/classes"/> <mytask message="message for ant task 1"/> <mytask message="message for ant task 2"/> <mytask message="message for ant task 3"/> </target> </project>
And the associated Java task:
//************************************************** import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; public class MyTask extends Task { private String message = null; public void setMessage(String msg) { message = msg; } public void execute() throws BuildException { System.out.println(this.getClass().toString() + "execute :" + message); } } //**************************************************
Some advise to easily create your task :
- Don't forget to add ant.jar which contains org.apache.tools.ant.Task to work faster.
- Download a example done with netbeans
- The command ' ant -diagnostics ' can give you many usefull information