Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Apache Ant Properties: Access Java System Properties, Environment Variables, and Runtime Inputs

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.

Java system properties

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.

SourceReference styleHow it is setTypical use
Java system property${user.home}Provided by the JVM running AntRuntime and host metadata
Environment variable${env.PATH}Imported with the Ant property task using an environment prefixOS-level paths and machine config
Command-line property${deploy.env}ant -Ddeploy.env=prodCI/CD and per-run overrides
Interactive input${release.version}Set with Ant input taskLocal/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 -D properties for CI/CD and environment-specific overrides.
  • Import environment variables with a clear prefix (for example, env) to avoid naming collisions.
  • Avoid interactive input tasks 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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

4 Open Source Alternatives to Slack for Team Chat: IRC, Let’s Chat, Mattermost, and Rocket.Chat

If you want Slack-like team communication with more control, these four open source options are a practical starting point. This guide compares their strengths, trade-offs, and how to run a short technical pilot.

Read More

jstack Utility Deep Dive: JVM Thread Dumps, Deadlocks, and Mixed Stacks

This guide explains how to use jstack to diagnose JVM hangs and deadlocks, including forced dumps, core-file analysis, and mixed Java/native stack traces. It also clarifies where jcmd fits in modern JDK 8+ troubleshooting guidance.

Read More

Open Source Scanning Software: Evaluate Legacy Tools and Build a Modern SCA Workflow

The original post listed several tool names but no implementation guidance. This revised guide explains what open source scanning means in DevSecOps, how to interpret those legacy names, and how to implement a practical CI scanning workflow.

Read More

Lyca Mobile USSD Shortcuts: Check Balance and Data Balance Quickly

Use these Lyca Mobile USSD shortcuts to check your prepaid balance and remaining data in seconds. This updated reference includes quick steps, a workflow diagram, and troubleshooting guidance.

Read More

Single Sign-On Implementations: Practical Comparison and Evaluation Guide

This guide expands a short 2015 link list of SSO tools into a practical DevOps reference. You will learn how SSO flows work, how to compare implementations, and how to validate integrations with real commands.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x