我有一个关于Ant和它的治疗环境变量的问题。为了说明我有一个小样本。
I have a question regarding Ant and its treatment of environment variables. To illustrate I have a small sample.
由于Ant构建文件的test.xml:
Given the Ant build file test.xml:
<project name="myproj" default="testProps"> <property environment="env"/> <target name="testProps"> <echo message="${env.MyEnvVar}"/> <echo message="${MY_PROPERTY}"/> </target> </project>和属性文件test.props:
And the properties file test.props:
MY_PROPERTY=${env.MyEnvVar}现在设置环境变量 MyEnvVar 到某一值(富在我的情况),并使用此命令行运行Ant:
Now set the environment variable MyEnvVar to some value (foo in my case) and run Ant using this command line:
ant -f test.xml -propertyfile test.props testProps我得到的输出是:
The output I get is:
[echo] foo [echo] ${env.MyEnvVar}我想知道的是是否有任何方式结构中的输入属性文件,这样我得到
What I would like to know is whether there is any way to structure the input properties file such that I get
[echo] foo [echo] foo这就是我想的名字在被替换的Ant脚本中的属性文件中的环境变量。注 - 我知道如何直接访问环境变量(如在这里完成)。我需要做的是利用一组期望在使用不同的名称定义相同属性的环境属性的一个集合Ant脚本的。因此,在属性文件架桥他们。想到
That is, I would like to name an environment variable in the properties file which is replaced within the Ant script. Note - I know how to access environment variables directly (as is done here). What I need to do is make use of a set of Ant scripts that expect one collection of properties in an environment that defines the same properties using different names. Thus the thought of "bridging" them in a properties file.
我使用Ant版本1.6.5。
I am using Ant version 1.6.5.
推荐答案您需要阅读 test.props 属性文件的之后的环境 - 你可以这样做使用另一个属性任务,即添加
You need to read the test.props property file after the environment - you could do so using another property task, i.e. add
<property file="test.props" />您现有的物业环境之后任务。
在全:
<property environment="env" /> <property file="test.props" /> <target name="testProps"> <echo message="${env.MyEnvVar}"/> <echo message="${MY_PROPERTY}"/> </target>当您提供性能的命令行这被构建的内容之前处理上的文件,但当时 $ {env.MyEnvVar} 尚未设置
When you supply the properties file on the command line this gets processed before the content of the build, but at that time ${env.MyEnvVar} is not yet set.
更多推荐
Ant可以扩大从属性的环境变量文件?
发布评论