Ant - Access environment variables

By xngo on June 29, 2019

Here is how you can access your environment variables. Note: Environment variables are specific to your system.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="EnvironmentVariables" name="EnvironmentVariables">
 
    <target name="EnvironmentVariables">
        <property environment="my_env" />
        <echo>
            Here are sample environment variables in my operating system:
            ${my_env.PATH}
            ${my_env.COMPUTERNAME}
            ${my_env.ANT_HOME}
            ${my_env.JAVA_HOME}
        </echo>
    </target>
 
</project>

More details can be found at http://ant.apache.org/manual/Tasks/property.html

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.