简体   繁体   中英

How can I change a config file variable using ant build?

I'm using Jboss 4/5 and have some .war .properties files with default configuration settings

I want to update these settings using information from the windows xp environment variables.

${env} in ant

Import enviroment variables before including your property file:

build.xml file:

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

test.properties file:

test = ${env.TEMP}

I needed to up the build number in several files. Since I needed to keep the formatting of the file as well as the comments, I used replaceregexp . Be careful when writing your regular expressions that you limit the expression to only find the instances that you care about.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM