How Ant echo environment variables

Ant has a build-in task Property that can access OS-specific environment variables, Property's parameter environment is the prefix to use when retrieving environment variables, plus the prefix and environment variables’name, we can directly echo or use its value.

Here is the example that echo environment variables in ANT.

Build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Here is how you can access your environment variables.
Note: Environment variables are specific to your system.
-->
<project basedir="." default="echoVariables" name="Echo Environment Variables">

<target name="echoVariables">
   <property environment="my_env" />
   <echo>
      Here are sample environment variables in my operating system:
      ${my_env.classpath}
      ${my_env.CommonProgramFiles}
      ${my_env.CommonProgramFiles(x86)}
      ${my_env.CommonProgramW6432}
      ${my_env.java_home}
   </echo>
</target>
</project>

Note that environment variables’ name in Ant are case-sensitive even if they are not on your operating system, so be careful write it(cannot always be uppercase.)

Here is the part of environment variable displayed in command line:

I ran this ant script, it echoed environment variables as below:

C:\temp>ant
Buildfile: build.xmlechoVariables:
[echo]
[echo] Here are sample environment variables in my operating system:
[echo] ,;C:\CommonProgram\Java\jdk1.5.0_08\lib
[echo] C:\Program Files (x86)\Common Files
[echo] C:\Program Files (x86)\Common Files
[echo] C:\Program Files\Common Files
[echo] C:\CommonProgram\Java\jdk1.5.0_08
[echo]BUILD SUCCESSFUL
Total time: 0 seconds
Оцените статью
ASJAVA.COM
Добавить комментарий

Your email address will not be published. Required fields are marked *

*

code