Home Tutorials Ant Value in the properties file overwrite the value in the build.xml
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Value in the properties file overwrite the value in the build.xml

Advertisement
In this section, you will learn how to create a build.properties file.

Value in the properties file overwrite the value in the build.xml

     

This example illustrates how to create a build.properties file in the C:\apache-tomcat-6.0.16\webapp\antBuild\build.properties and overwrite it's properties in the build.xml file. In this example, <property name="build.path"> is used to map the path of build.xml and build.properties file, <property url="http://localhost:8080/antBuild/build.properties"> is used to root url of properties file, <property file="build.properties" prefix="imported"> is used to define the property of the build.properties file and  <property environment="env"> is used to create an environment variable that is 'env'. Now the target <target name="built-in-properties"> is used to find base directory name, ant file name, version of ant, project name and version of java. The target <target name="build.path"> is used to print the file name and path of file and finally <target name="environment"> is used to print the processor architecture name and operating system name and print the ant home directory name.

Source code of build.xml:

<project name="Properties" basedir="." default="environment">

  <property name="build.path" value="${basedir}/build.xml:${basedir}/build.properties"/>
  <property url="http://localhost:8080/antBuild/build.properties"/>
  <property file="build.properties" prefix="imported"/>
  <property environment="env"/>
  
  <target name="built-in properties">
  <echo message="The base directory is: ${basedir}"/>  
  <echo message="The ant file is: ${ant.file}"/>
  <echo message="The Ant version is: ${ant.version}"/> 
  <echo message="The Project name is: ${ant.project.name}"/> 
  <echo message="The Java version is: ${ant.java.version}"/> 
  </target>

  <target name="build.path" depends="built-in properties">
  <echo message="The File name is: ${basedir}${file.separator}build.xml"/>
  <echo message="Path structure: ${basedir}${file.separator}build.xml${path.separator}
   ${basedir}${file.separator}build.properties"/>
  </target>

  <target name="environment" depends="build.path">
  <echo message="Built on: ${env.OS} ${env.PROCESSOR_ARCHITECTURE}"/>
  <echo message="ANT_HOME Directory name: ${env.ANT_HOME}"/>
  </target>

</project>

source code of build.properties:

property.example=Local File
property.file.example=build.properties

Run this program on command prompt - the following output will be displayed.


Download Source Code

     

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 6, 2008

Ask Questions?    Discuss: Value in the properties file overwrite the value in the build.xml  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com