MHAR
MHAR

Reputation: 1

Ant build.xml not reading env properties

I have a cmd script file, which sets all the environment values and invoke ant class to build the java project.

I have:

<property environment="env"/> 

set in build.xml and

<property name="CD" value="${env.CDTEC}"/>. 

build.xml unable to read these env values set from the cmd script file. If I echo the values from command prompt that prints, but not from the ant.xml file. Getting the error as

BUILD FAILED
c:\Users\test\Projects\Spring testing\build.xml:85: c:\Users\test\Projects\Spring testing\${env.CDTEC}\lib does not exist.

I added echo message in build.xml as

<echo message="Message from ${this.CDTEC} Client" />

and printing that as

'Message from {env.CDTEC} Client'. 

Command prompt is printing these values but Ant is not able to access these env values, any idea why?

Upvotes: 0

Views: 2872

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77951

Is the environment variable set externally to ANT?

Example

Setting the variable and calling ANT

$ CDTEC=hello ant
Buildfile: /....../build.xml

build:
     [echo] CDTEC=hello

build.xml

<project name="demo" default="build">

  <property environment="env"/>

  <target name="build">
    <echo message="CDTEC=${env.CDTEC}"/>
  </target> 

</project>

Upvotes: 1

Related Questions