Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating files inside an existing WAR file

Tags:

ant

I am trying to update files inside an existing WAR file using the ANT WAR task. I need to replace a set of xml files in a folder in WAR with new ones from my HDD.

<war destfile="myApp.war" update="true" >
    <zipfileset dir="<PathToStubsFolderOnHDD>" includes="**/*.xml" prefix="<PathToStubsFolderInWAR>"/>
</war>

This works fine if the original WAR does not have xmls with same name. However if the original WAR contains xmls with same name; WAR task does not update them with files from HDD.

The ANT WAR task documentation reads:

update | indicates whether to update or overwrite the destination file if it already exists. Default is "false".
duplicate | behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add".

if i use update="false"; all other files in the original WAR are deleted and only the new xmls stored.

using duplicate="add" didnot have any effect either.

Any suggestions on how this can be achieved??

like image 851
Nirmal Patel Avatar asked Feb 05 '10 20:02

Nirmal Patel


1 Answers

Seems that with update=true option, the war file is newer than the files that you want to update. Someone suggest to apply the touch task with '0' to workaround the problem.

The zip task checks only if the source files you whish to add to an existing zip are more recent than the zip. A workaround would be to <touch millis="0" /> the zip file before adding.

Or you could do the reverse stuff:

Performing a touch before the war task on XML file(s) makes it work.

like image 68
Aito Avatar answered Oct 29 '22 18:10

Aito