Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the path environment variable from ant script

How to set the path environment variable from ant script

like image 304
user855 Avatar asked Apr 09 '11 20:04

user855


People also ask

How can you set Environment Variables from the command line?

To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").

What should ANT_HOME be set to?

ANT_HOME should be set to the directory where ant is installed. e.g. Show activity on this post. If you have missing files/directories, unzip the apache-ant-1.9.

Why do we set PATH environment variable?

The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/. profile file.


1 Answers

Is this for an <exec> task?

You can set environment variables when you run an <exec> task:

<exec executable="${my.command}">     <env key="foo" value="bar"/>     <arg line="some value"/> </exec> 

You can use <property environment="env"/> to expand the path:

<property environment="env"/> <exec executable="${my.command}">    <env key="PATH" value="${env.PATH}:${my.directory}"/> </exec> 

If this is for some custom task that requires an environment variable, but doesn't allow you to set the environment variable in the task if one isn't set, you can try setting it in:

<property environment="env"/> <property name="env.foo" value="bar!bar"/> 

This might set an environment variable called foo to the value of bar!bar!. I remember something about this, but wasn't able to get it to work.

The other thing you can do is have one ant script execute another and have the first ant script set the environment value. I did this when I had to set ANT_OPT.

like image 115
David W. Avatar answered Sep 21 '22 21:09

David W.