How to set the path environment variable from ant script
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 ").
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With