Originally published on 2009-06-20; fully revised and updated.
If you use Apache Ant, property expansion via ${name} is the core mechanism for build-time configuration. This guide shows how to read Java system properties directly, import environment variables, pass values with -D, and use interactive input only where it makes sense.
This revised article expands the original quick tip from DevOpsSchool into a practical reference.

Property sources in Ant at a glance
In Ant build files, you reference a property as ${property.name}. Values can come from multiple sources during a build run.
| Source | Reference style | How it is set | Typical use |
|---|---|---|---|
| Java system property | ${user.home} | Provided by the JVM running Ant | Runtime and host metadata |
| Environment variable | ${env.PATH} | Imported with the Ant property task using an environment prefix | OS-level paths and machine config |
| Command-line property | ${deploy.env} | ant -Ddeploy.env=prod | CI/CD and per-run overrides |
| Interactive input | ${release.version} | Set with Ant input task | Local/manual runs |
Read Java system properties directly
You can use common JVM properties directly in your build file without extra setup.
${user.name}${user.dir}${user.home}${java.version}
<project name='sys-props-demo' default='show-system-props'>
<target name='show-system-props'>
<echo message='user.name = ${user.name}'/>
<echo message='user.dir = ${user.dir}'/>
<echo message='user.home = ${user.home}'/>
<echo message='java.version = ${java.version}'/>
</target>
</project>Code language: HTML, XML (xml)
Import environment variables with a prefix
To expose OS environment variables in Ant properties, use the property task with an environment prefix (for example, env). Then reference values as ${env.VARIABLE_NAME}.
<project name='env-demo' default='show-env'>
<target name='show-env'>
<property environment='env'/>
<echo message='PATH = ${env.PATH}'/>
<echo message='HOME = ${env.HOME}'/>
<echo message='USERPROFILE = ${env.USERPROFILE}'/>
</target>
</project>Code language: HTML, XML (xml)
Pass properties at runtime with -D
For pipeline-friendly builds, pass values at invocation time so you can reuse the same build file across environments.
ant -Ddeploy.env=staging -Dbuild.number=123 package
ant -Ddeploy.env=prod deploy
Inside build.xml, consume those runtime values with normal property syntax.
<target name='package'>
<echo message='Deploy environment: ${deploy.env}'/>
<echo message='Build number: ${build.number}'/>
</target>Code language: HTML, XML (xml)
Prompt for input during local runs
Ant can prompt for ad hoc input. This is useful for local/manual execution, but usually unsuitable for non-interactive CI jobs.
<target name='ask-version'>
<input addproperty='release.version' message='Enter release version'/>
<echo message='Release version: ${release.version}'/>
</target>Code language: HTML, XML (xml)
Property resolution workflow
flowchart TD
A[Task needs a property] --> B{Set by D argument}
B -- yes --> C[Use command line value]
B -- no --> D{Set in build or property file}
D -- yes --> E[Use first assigned value]
D -- no --> F{Available as Java system property}
F -- yes --> G[Use system property]
F -- no --> H{Imported from env prefix}
H -- yes --> I[Use env prefixed value]
H -- no --> J[Optional input or fail]
Best practices and common pitfalls
- Use
-Dproperties for CI/CD and environment-specific overrides. - Import environment variables with a clear prefix (for example,
env) to avoid naming collisions. - Avoid interactive
inputtasks in automated pipelines. - Do not echo sensitive values (tokens, passwords, keys) into logs.
- Keep default values in the build file and override only what is needed per run.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals