Ant - setting Environment variables
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sam_Cavenagh
Posted On:   Wednesday, March 10, 2004 08:32 PM

I am want to uses Ant to do CVS tasks. To get ant to do this i need to have CVS on my path. I also want to share the ant script with other users on the network. CVS is located on a network drive that everyone can access i want ant to set that location into path environment variable when it runs so each user doesnt have to go and change there path. Ive tried all kinds of things but it doesnt work eg **** CVS_SERVER: ${env.CVS_SERVER} **** **** Path: ${env.Path} **** ive even tried making bat file. Didnt work. Can i set an environment variable in ant ??    More>>

I am want to uses Ant to do CVS tasks. To get ant to do this i need to have CVS on my path. I also want to share the ant script with other users on the network. CVS is located on a network drive that everyone can access i want ant to set that location into path environment variable when it runs so each user doesnt have to go and change there path.

Ive tried all kinds of things but it doesnt work

eg

			




**** CVS_SERVER: ${env.CVS_SERVER} ****
**** Path: ${env.Path} ****


ive even tried making bat file. Didnt work.

Can i set an environment variable in ant ??    <<Less

Re: Ant - setting Environment variables

Posted By:   Mert_Nuhoglu  
Posted On:   Thursday, April 22, 2004 07:35 AM

There is a specific task to set environment variables from inside the ant.



Under the CoreTasks/exec. You should use "env" nested element.



There is a sample from ant documentation:











Actually I tried myself to set environment variable with this element. But I couldn't. I am not sure why it didn't.



Once I tried this:















I guess the error with this code was that more than one nested element is not allowed under exec.



Then I tried this:













It didn't work neither. In the Ant documentation, it states that the parameter line is not very predictable. But I need to use this, because I want to give more than one command. The other option value permits only one line of command.



Does anybody know how to do this in the correct way?

Re: Ant - setting Environment variables

Posted By:   Anonymous  
Posted On:   Monday, March 15, 2004 04:21 AM

You can not set env-variables from Ant in a durable way. provides a way to pass env-variables to a call. But these settings are lost when that call finished. On Windows you can use the setx command.

setx help


SETX: This program is used to set values in the environment
of the machine or currently logged on user using one of three modes.

1) Command Line Mode: setx variable value [-m]
Optional Switches:
-m Set value in the Machine environment. Default is User.

2) Registry Mode: setx variable -k hivekey...value
Optional Switches:
-m Set value in the Machine environment. Default is User.

3) File Mode: setx variable -f file {-a x,y | -r x,y "string"} [-d d] [-x] [-m]
Required Switches:
-f file : Specify file name to use.
-a x,y : Specify absolute coordinates and offset.
-r x,y "string" : Specify coordinates and offset relative to string.
Optional Switches
-d ,: etc. : Specify additional delimiters.
-x : Displays file coordinates. Switches -a -r -e ignored!!
-m : Set value in the Machine environment. Default is User.

For more information and example use: SETX -i
About | Sitemap | Contact