·  ANT – Tags – <taskdef/>

 

- Info:

  - Taskdef is used to create cusom tags implemented by custom JAVA classes.

  - In this example custom task takes one parameter.

  - Parameter is displayed on the screen by custom JAVA class which implements that task.

 

- Example:

  - Create ANT Script Test.xml

  - Create JAVA Console Application D:\Temp\ANT\Test.java

 

    Test.xml

    <?xml version="1.0" encoding="UTF-8"?>

    

    <project name="MyAntProject" default="default" basedir=".">

          

      <taskdef  name      = "taskHello"

                classname = "Test"

                classpath = "."/>

          

       <target name="default">     

         <taskHello par1="Hello world!" />       

       </target>  

    

    </project>

 

    Test.java

    import org.apache.tools.ant.Task;

    import org.apache.tools.ant.BuildException;

    

    public class Test extends Task {

      

      private String par1;

 

      public  void   setPar1(String in) { par1 = in; } 

        

      public void execute() throws BuildException {

        System.out.println("Task called with:" + par1);   

      }

      

    }

 

- Test:

  - Start MSDOS

  - cd D:\Temp\ANT

  - javac -cp D:\Installed\Programming\apache-ant-1.7.1\lib\ant.jar Test.java

  - ant.bat -buildfile Test.xml