Changing the properties file inside a jar using Ant

I have settings in the properties file located in the bank, which I want to change during the build using ant. Ideally, if I can find a specific text in a properties file and easily replace it, I would like to do it, but I don't know how to do it.

So, I thought that I could overwrite it with another properties file that already has new settings. A box already exists in my directory, and the hierarchy of my jar is as follows:

food.jar
/com/food/donut.properties
some file...
some file...

If I had another donut.properties file with another parameter located in a different directory. How to rewrite it with ant?

Thanks for the help, very grateful!

EDIT:

With the following code, I was able to copy the properties file to the jar. But whenever I try to copy a new properties file into the same directory of the old properties file, it is not replaced. (ie if I change the prefix to "com", I can see that the new properties file is inserted into the jar. If the prefix is ​​changed to com / food, nothing is replaced. What am I doing wrong?

    <jar destfile="${dist.dir}/food.jar" update="true">
        <zipfileset file="donut.xml" prefix="com/food/" />
    </jar>
+5
source share
2 answers

ant task documentation jar says:

, , JAR . "", JAR . no ( ), JAR . Zip-. , ZIP . , Ant .

, , jar. .

temp, , - true, temp.

+3

Ant 1.8.x

1)
, :

<propertyfile file="/path/to/propertyfile/foo.properties">
 <!-- will change an existing key named 'somekey' with the value 'foo' inplace -->
 <entry key="somekey" value="foo"/>
</propertyfile>

. Ant

2)
:

<jar destfile="/path/to/your/foo.jar" update="true">
 <fileset dir="/path/to/propertyfile" includes="*.properties"/>
</jar>

:

<jar destfile="/path/to/your/foo.jar" update="true">
 <mappedresources>
  <fileset dir="." includes="*.properties"/>
   <globmapper from="*.properties" to="/com/xml/*.properties"/>
 </mappedresources>
</jar
+5

All Articles