Ant ignores attempt to override LANG environment variable

We need to check the java assembly with languages ​​set to different values. I can manually (i.e. via export LANG=en_DK.UTF-8

and export LANG=en_DK

) verify that the unit tests run with the ant build script behave differently, but I need to set the environment variable from ant. I tried to install it using these methods (with shell $LANG

set to en_DK.UTF-8

):

  • using -D

    on the command line:ant -DLANG=en_DK

  • using a file build.properties

    with a line LANG=en_DK

    in it
  • using the following instructions in your 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 from -debug

, ant reports that:

Override ignored for property "LANG"

      

What can I do to set the environment variable LANG

from ant?

+2


a source to share


2 answers


ANT Properties are immutable ,

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

      

can be interpreted by ant as trying to override a value LANG

that is already present while storing all environment variables in ANTENV

(with <property environment="ANTENV"/>

).



So, you need to store to store this value in a separate property.

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

      

+1


a source


Assuming your "Java build test" is being invoked <java>

, you can use the fork-flag and pass properties on 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>

      

0


a source







All Articles