How to read properties file using ANT

Suppose You have to access some properties (from a file), which are already defined in my build file. To be able to access the properties We can use the build attribute of the property task. 

build.properties

#Release information 
#Thu Oct 14 16:25:12 CEST 2004
build.number=115
release.version=0.4
release.name=framework
 
Ant Example Target

<target name="read.properties">    
  <!-- Read the properties from the release of the framework -->
  <property file="build.properties" prefix="build"/>
  <echo message="${build.build.number}"/>
  <echo message="${build.release.version}"/>
  <echo message="${build.release.name}"/>    
</target> 
 
Output

Buildfile: C:\build.xml
read.properties:
  [echo] 115
  [echo] 0.4
  [echo] framework
BUILD SUCCESSFUL
Total time: 3 seconds

Comments

Popular posts from this blog

Streaming Spring boot logs to ELK stack

Keyboard Shortcuts That Work in All Web Browsers

How TOTP Works: Generating OTPs Without Internet Connection