Ant 忽略覆盖 LANG 环境变量的尝试

发布于 2024-09-01 22:16:01 字数 726 浏览 1 评论 0 原文

我们需要使用设置为不同值的语言来测试 java 构建。我可以手动(即通过 export LANG=en_DK.UTF-8export LANG=en_DK)测试使用 ant 构建脚本运行的单元测试的行为是否不同,但我需要从ant设置环境变量。我尝试使用这些方法进行设置(将 shell $LANG 设置为 en_DK.UTF-8):

  1. 在命令上使用 -D line: ant -DLANG=en_DK
  2. 使用 build.properties 文件,其中包含 LANG=en_DK 行,并
  3. 在构建中使用以下语句。 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):

  1. using -D on the command line: ant -DLANG=en_DK
  2. using a build.properties file with the line LANG=en_DK in it
  3. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那请放手 2024-09-08 22:16:01

ANT 属性是不可变的

<property name="ANTENV.LANG" value="en_DK"/>

可能会被 ant 解释为尝试覆盖将所有环境变量存储在 ANTENV 中时已存在 LANG 值(使用 )。

因此,您需要将该值存储在单独的属性中。

<property name="MY.LANG" value="${env.LANG}" />

ANT Properties are immutable,

<property name="ANTENV.LANG" value="en_DK"/>

may be be interpreted by ant as an attempt to override the LANG value already present when storing all the environment variables in ANTENV (with <property environment="ANTENV"/>).

So you need to store to store that value in a separate property.

<property name="MY.LANG" value="${env.LANG}" />
柠栀 2024-09-08 22:16:01

假设您的“测试 java 构建”是通过调用 完成的,您可以使用 fork-flag 并将属性传递给新创建的进程。以下是 Ant 文档 中的示例:

  <java classname="test.Main"
        fork="yes" >
    <sysproperty key="DEBUG" value="true"/>
    <arg value="-h"/>
    <jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
  </java>

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:

  <java classname="test.Main"
        fork="yes" >
    <sysproperty key="DEBUG" value="true"/>
    <arg value="-h"/>
    <jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
  </java>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文