ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cyril Sagan" <>
Subject RE: replace an entry in a zip file?
Date Thu, 14 Jun 2007 16:11:44 GMT
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:

    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="**/*" />

        <!-- Use zip to add my manifest without having Ant -->
        <!-- try to merge with its default one, that is:   -->
        <!-- main/org/apache/tools/ant/  -->
        <zip destfile="test.jar" basedir="work" update="true">
            <zipfileset dir="." includes="my_manifest"



-----Original Message-----
From: RADEMAKERS Tanguy [] 
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?

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.


To unsubscribe, e-mail: For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message