Saturday, July 14, 2012

Reading from properties file using Ant

Here is an example ant target which explains how to read from a properties file in ant.
//Build.xml
  1. <project name="Sample" default="delete-dir" basedir=".">
  2.     <!-- Read the properties file -->
  3.     <property file="config/config.properties" prefix="config"/>
  4.        
  5.     <!-- Using the property value(read from file) in ant's preperty attribute-->
  6.     <property name="build.loc" value="${config.build_dir_loc}" />
  7.    
  8.     <!-- Delete directories that are not needed -->
  9.     <target name="delete-dir" >
  10.         <delete dir="${build.loc}"/>
  11.         <echo> /* Directory deleted successfully ! */ </echo>
  12.     </target>
  13. </project>
In the above ant script the file from which we read data is 'config.properties' (present inside 'config' folder)which is shown below:
//config.properties
  1. username = aksahu
  2. password = aksahu123
  3. url = http://quickprotech.blogspot.in/
  4. port = 4444
  5. build_dir_loc = E:/temp/build