0

Take a properties files like

#File One
#Section One
sect1.number=Test1
sect1.sample=Test2
sect1.test=Test3

#Section Two
sect2.number=Test1
sect2.sample=Test2
sect2.test=Test3

After running this ant:

<property file="sample1.properties"/>
<propertyfile file="sample1.properties">
   <entry key="sect1.number" value="ABC"/>
   <entry key="sect1.sample" value="B"/>
   <entry key="sect1.test" value="ABC"/>
   <entry key="sect2.number" value="B"/>                    
   <entry key="sect2.sample" value="ABC"/>
   <entry key="sect2.test" value="B"/>
</propertyfile>
 

The properties file will end as:
#Updated on blah
sect2.sample=ABC
sect2.test=B
sect1.sample=B
sect1.number=ABC
sect2.number=B
sect1.test=ABC

Note the comments are gone and the order is different.

What am I doing wong, is there a work around?

Grae

GC_
  • 1,673
  • 6
  • 23
  • 39

1 Answers1

1

I guess you are using an Ant version earlier than 1.8.

Since 1.8, the propertyfile task defaults to a "layout preserving" mode which retains comments (and possibly retains property order, but I'm not sure about that).

In that version, you can revert to the old behaviour by specifying jdkproperties=true

Original file

$ cat sample1.properties.original
#File One
#Section One
sect1.number=Test1
sect1.sample=Test2
sect1.test=Test3

#Section Two
sect2.number=Test1
sect2.sample=Test2
sect2.test=Test3

Version created using your build file in my Ant 1.8.2 environment

$ cat sample1.properties.default
#Mon, 11 Jun 2012 14:39:08 +0000
#File One
#Section One
sect1.number=ABC
sect1.sample=B
sect1.test=ABC

#Section Two
sect2.number=B
sect2.sample=ABC
sect2.test=B

Version created using your build file in my Ant 1.8.2 environment but specifying jdkproperties="true"

$ mv sample1.properties sample1.properties.jdk
$ cat !$
cat sample1.properties.jdk
#Mon Jun 11 14:41:01 GMT 2012
sect2.test=B
sect1.test=ABC
sect2.sample=ABC
sect2.number=B
sect1.sample=B
sect1.number=ABC

My ant environment

$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
ewan.chalmers
  • 16,145
  • 43
  • 60