Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Ant property file

May 25, 2021 Apache Ant

Table of contents

Ant property file

When you only need to set a small number of properties, you can choose to set them directly in the build file. However, for large projects, it is a good idea to store the information that sets the properties in a separate file.

Storing property information in a separate file provides the following benefits:

  • It allows you to reuse the same build file, which uses different property settings in different execution environments. For example, building property files can be maintained independently in DEV, TEST, and PROD environments.
  • This processing is beneficial when you do not know the value of the property in advance (for example, in a real-world environment). This allows you to perform build operations in other environments after you know the property values.

There are no hard rules here, but in general, property files are named and are stored on the same .xml as build files. You can create multiple based on the deployment environment, such as: web security and

The build..xml files associated with it are shown in the following example:


<?xml version="1.0"?>
<project name="Hello World Project" default="info">

   <property file=""/>

   <target name="info">
      <echo>Apache Ant version is ${ant.version} - You are at ${sitename} </echo>


# The Site Name

Notice that in the above exercise, sitename is a custom property that maps after execution to a Web site "Property". Y ou can declare any number of properties in this way. In the example above, there is also a custom property buildversioin that indicates the version number currently built.

In addition to the two properties mentioned above, Ant provides additional built-in properties, which were mentioned in the previous section, but we'll give the related properties again.

Property Describe
ant.file Represents the absolute path of buildfile.
ant.version Represents the version of Ant.
basedir Represents the absolute path to the project base directory.
ant.jave.version Represents the version of the JDK detected by Ant. Represents the name of the project currently specified.
ant.project.default-target Represents the default target for the current project.
ant.project.invoked-targets Represents a series of comma-separated targets that are called by the current project.
ant.core.lib Represents the absolute path to the Ant jar file.
ant.home Represents the root of the Ant installation.
ant.library.dir Represents the Ant library, typically the root of ANT_HOME/lib file.

In the example of this section, the Ant built-in property we use is the ant.version property.