ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Donie <>
Subject RE: Access environment variables within ANT?
Date Tue, 13 Feb 2001 15:53:41 GMT
Also, in ant 1.3 b1 and after, there is a way to get to all environment
variables without using -D on the command line. I have this in the beginning
of my build.xml, (not inside any targets).

  	This allows access to all OS environment variables - just use syntax
  <property environment="myEnv" />

Then inside a target you can access any environment variable - see the
testing message where I echo my CVSROOT:

  <target name="init">
    <!-- Create the time stamp -->
    	<format property="TIME_NOW" pattern="hh:mm:ss" />
    <echo message="Building ${} on ${Machine} in ${basedir}
starting at ${TIME_NOW} on ${TODAY}" />
    <echo message="Testing: ${myEnv.CVSROOT}" /> 

-----Original Message-----
From: Atul V. Setlur []
Sent: Tuesday, February 13, 2001 9:37 AM
Subject: Re: Access environment variables within ANT?

> Is it possible to access environment variables within ANT? e.g. If I
> an environment variable MICK, is there any way of access in within ant, ie
> ${env.MICK}

You need to specify it as a Java property i.e.,  -D<propertyName>=<value>
specified on the command line when Ant is launched. Please refer to the
documentation under "Running Ant" for more information. I am including the
relevant piece below.

You can also set properties which override properties specified in the
buildfile (see the property task). This can be done with the
-D<property>=<value> option, where <property> is the name of the property
<value> the value. This can also be used (and is the only way since Java can
not access them) to have access to your environment variables, just pass
-DMYVAR=%MYVAR% (Windows) or -DMYVAR=$MYVAR (Unix) to Ant, you can then
these variables inside your build-file as ${MYVAR}.


View raw message