wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to set environmental variables from ANT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to set environmental variables from ANT?" Watch "How to set environmental variables from ANT?" New topic
Author

How to set environmental variables from ANT?

Micky Pat
Greenhorn

Joined: May 03, 2006
Posts: 18
Hi ranchers,

I know this is not clean, but I would need to get this to work (don't ask me why... )

Hi need to set 2 environmental variables, MYTESTVARIABLE1 and MYTESTVARIABLE2, set from ant.
Note that I preset MYTESTVARIABLE1=ggg1 and MYTESTVARIABLE2=ggg2.
Now, if I run the following ant script

<project basedir="." default="test" name="Setting env variable">

<property environment="env"/>
<property name="env.MYTESTVARIABLE1" value="ttt1"/>
<property name="env.MYTESTVARIABLE2" value="ttt2"/>

<target name="test">
<echo message = "Variable 1 is = ${env.MYTESTVARIABLE1}"/>
<echo message = "Variable 2 is = ${env.MYTESTVARIABLE2}"/>
<echo message = "ANT_HOME is set to = ${env.ANT_HOME}"/>
<echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/>
<echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>
</target>
</project>

if I run this, the output will be

test:
[echo] Variable 1 is = ggg1
[echo] Variable 2 is = ggg2
[echo] ANT_HOME is set to = ${env.ANT_HOME}
[echo] Number of Processors = ${env.NUMBER_OF_PROCESSORS}
[echo] ANT_HOME is set to = ${env.ANT_HOME}


which is not what I am expecting...

What's wrong? Is there a way of setting environmental variables?

Regards
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

Micky,
The property task can only be used for getting the value of an already set environment variable. There is no way to set environment variables through Ant. You would need to call Ant's exec task and pass the command line (for your operating system) to set the value of an environment variable.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set environmental variables from ANT?