Ant可以扩大从属性的环境变量文件? [英] Can Ant expand environment variables from a properties file?

查看:94
本文介绍了Ant可以扩大从属性的环境变量文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于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可以扩大从属性的环境变量文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆