ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: replace an entry in a zip file?
Date Thu, 14 Jun 2007 16:33:09 GMT
Your build file *nearly* works!
You are been defeated by the timestamp check.
Zip  will only update a zip file with files that are
newer that the files that are in the zip file.
For the manual page:

"""
Please note that ZIP files store file modification times with a
granularity of two seconds. If a file is less than two seconds newer
than the entry in the archive, Ant will not consider it newer.
"""

There does not seem to be "force" attribute to get the zip task
to ALWAYS update the file.

Using the update option and multiple adding of files to zip/jar
files are always problematic. (For example, What to do with deleted files)
I would suggest that you should refactor your build file so
that you just have one zip task (per jar file). for example:
   <target name="go">
       <!-- build trivial sample jar -->
       <mkdir dir="work" />
       <touch file="work/a" />
       <touch file="work/b" />

       <zip destfile="test.jar">
           <fileset dir="work" includes="**/*" />
           <zipfileset dir="." includes="my_manifest"
                               fullpath="META-INF/MANIFEST.MF"/>
       </zip>
   </target>

Peter

On 6/14/07, Cyril Sagan <Cyril.Sagan@sas.com> wrote:
> Thanks for your reponse.  However, this does not work for me in Ant 1.6.5.
> Note that my goal is to *replace* a file that's already in the zip.
>
> Seems like the best solution would be for the duplicate attribute to support a "replace"
option.
>
> FWIW, I'm doing this to control my jar manifest.  I can't use <jar> because Ant
merges with its default manifest.  I'm having a hard time employing this advice from the Ant
doc:
>
> http://ant.apache.org/manual/CoreTasks/manifest.html
>
>     If you find that Ant generates manifests incompatible with your
>     runtime, take a manifest it has built, fix it up however you need
>     and switch to using the <zip>  task to create the JAR, feeding in
>     the hand-crafted manifest.
>
> Here's my build.xml:
>
> <?xml version="1.0"?>
> <project name="manifest_test" default="go">
>
>     <target name="go">
>         <!-- build trivial sample jar -->
>         <mkdir dir="work" />
>         <touch file="work/a" />
>         <touch file="work/b" />
>
>         <jar jarfile="test.jar" update="true">
>             <fileset dir="work" includes="**/*" />
>         </jar>
>
>         <!-- Use zip to add my manifest without having Ant -->
>         <!-- try to merge with its default one, that is:   -->
>         <!-- main/org/apache/tools/ant/defaultManifest.mf  -->
>         <zip destfile="test.jar" basedir="work" update="true">
>             <zipfileset dir="." includes="my_manifest"
>                                 fullpath="META-INF/MANIFEST.MF"/>
>         </zip>
>     </target>
> </project>
>
> Thanks.
>
> --Cyril
>
>
> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com]
> Sent: Thursday, June 14, 2007 5:23 AM
> To: Ant Users List
> Subject: RE: replace an entry in a zip file?
>
> Hello Cyril,
>
> >GOAL:  To replace one entry in a zip file with an updated file.
> >
> >I cannot find an elegant way to do this, short of <unzip>'ing the
> >archive, replacing the file of interest and then re-<zip>.  It seems
> >there should be a better way.  Can anyone help?
> >
> >Thanks.
> >
> >--Cyril
>
> If you use the update attribute of the zip task - it will "refresh" the zip with the
file or files you send it, without changing or removing the other files in the archive. You
may still need to extract the files of interest from the zip if you don't have them elsewhere,
but you don't need to explode the whole zip just to change a few files.
>
> Regs,
> /t
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail:
user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message