我们需要使用设置为不同值的语言来测试 java 构建。我可以手动(即通过 export LANG=en_DK.UTF-8
和 export LANG=en_DK
)测试使用 ant 构建脚本运行的单元测试的行为是否不同,但我需要从ant设置环境变量。我尝试使用这些方法进行设置(将 shell $LANG
设置为 en_DK.UTF-8
):
- 在命令上使用
-D
line: ant -DLANG=en_DK
- 使用
build.properties
文件,其中包含 LANG=en_DK
行,并
- 在构建中使用以下语句。 xml 文件(抱歉格式问题,否则我无法显示它)::
使用
<property environment="ANTENV"/>
<property name="ANTENV.LANG" value="en_DK"/>
三种可能性中的任何一种,当使用 -debug
运行时,ant 报告:
Override ignored for property "LANG"
我能做什么从 ant 中设置 LANG
环境变量?
We need to test a java build with the languages set to different values. I can manually (i.e. via export LANG=en_DK.UTF-8
and export LANG=en_DK
) test that the unit tests run with the ant build script behaves differently, but I need to set the environment variable from ant. I have tried setting it using these methods (with the shell $LANG
set to en_DK.UTF-8
):
- using
-D
on the command line: ant -DLANG=en_DK
- using a
build.properties
file with the line LANG=en_DK
in it
- using the following statements in the build.xml file (sorry for the formatting, I can't get SO to display it otherwise):
:
<property environment="ANTENV"/>
<property name="ANTENV.LANG" value="en_DK"/>
Using any of the three possibilities, and when run with -debug
, ant reports that:
Override ignored for property "LANG"
What can I do to set the LANG
environment variable from within ant?
发布评论
评论(2)
ANT 属性是不可变的,
可能会被 ant 解释为尝试覆盖将所有环境变量存储在
ANTENV
中时已存在LANG
值(使用
)。因此,您需要将该值存储在单独的属性中。
ANT Properties are immutable,
may be be interpreted by ant as an attempt to override the
LANG
value already present when storing all the environment variables inANTENV
(with<property environment="ANTENV"/>
).So you need to store to store that value in a separate property.
假设您的“测试 java 构建”是通过调用
完成的,您可以使用 fork-flag 并将属性传递给新创建的进程。以下是 Ant 文档 中的示例:Assuming that your "test a java build" is done by a call to
<java>
, you could use the fork-flag and pass properties to the newly created process. Here's an example from the Ant documentation: