·  ANT – Examples – <taskdef/> – Changes value of property given as parameter

 

- Info:

  - Task takes one parameter which is property name and it changes its value.

  - New value is then written in Dest.txt.

 

- Example:

 

    Test.xml

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

 

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

    

      <property name      = "myProp" value="12"/>

    

      <taskdef  name      = "prop"

                classname = "SetProperty"

                classpath = "C:\Installed\Programming\Tomcat50\webapps\myproject"/>

    

      <target   name      = "default">

        <prop   par1      = "myProp"/>

        <filter token     = "propValue"

                value     = "${myProp}"/>

        <copy   file      = "C:\Installed\Programming\Tomcat50\webapps\myproject\Src.txt"

                tofile    = "C:\Installed\Programming\Tomcat50\webapps\myproject\Dest.txt"

                overwrite = "yes"       

                filtering = "true"/>

      </target>

    

    </project> 

    

    SetProperty.java

    import org.apache.tools.ant.Task;

    import org.apache.tools.ant.BuildException;

    

    public class SetProperty extends Task {

      

      private String par1;

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

        

      public void  execute() throws BuildException {  

        System.setProperty(par1,"Property was set to 1000.");

      }

      

    }

    

    Src.txt

    @propValue@

    

    Dest.txt

    12