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.

<?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" />
      Here are sample environment variables in my operating system:

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:

Buildfile: build.xmlechoVariables:
[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
Total time: 0 seconds
Оцените статью
Добавить комментарий

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