简体   繁体   中英

ant reads values from properties entries and write back in a new line

In my Java project, I have three values in an existing properties file (version info file): Their values will be different for each build.

value1=1
value2=2
value3=3

I want to use ant to read them and write them back at the end of the same properties file as this format: if the line exist, overwrite it.

values=value1.value2.value3  i.e. values=1.2.3

How to do this?


Resolved:

I have figured out:

  1. use <loadproperties> to load the properties.
  2. use value1 , value2 and value3 as properties with ${value1} to get value and then write to the file with <propertyfile> .

If you don't actually need to read the original properties, you could do this in one step:

<replaceregexp
    file="foo.properties"
    flags="g"
    match="value(\d)"
    replace="\1"
/>

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