如何使用ant build更改配置文件变量?

时间:2009-12-23 19:44:11

标签: windows ant jboss properties build

我正在使用Jboss 4/5并拥有一些带有默认配置设置的.war .properties文件

我想使用来自windows xp环境变量的信息更新这些设置。

蚂蚁

中的

$ {env}

2 个答案:

答案 0 :(得分:4)

在包含属性文件之前导入环境变量:

build.xml 文件:

<target name="build">
   <!-- load enviroment properties -->
   <property environment="env" />
   <property file="test.properties" />
   <echo>test: ${test}</echo>
</target>

test.properties file:

test = ${env.TEMP}

答案 1 :(得分:1)

我需要在几个文件中提升内部版本号。由于我需要保留文件的格式以及注释,因此我使用了replaceregexp。在编写正则表达式时要小心,限制表达式只能找到你关心的实例。

<replaceregexp 
    file="${dir.project}/build.properties"
    match="(build\.number[ \t]*=).*"
    replace="\1${build.number}"
    flags="g"
/>