Unzip specific zip file from nested zip file using ANT

Tags: , , ,

I have a zip file ex. ‘test.zip’ that contains 2 more zip files within it – A.zip and B.zip. I want to only extract contents of A.zip and leave B.zip untouched.

I did try out the below code snippet, but found no luck yet –

<unzip src="test.zip" dest="test_dir">
            <fileset dir="test_dir">
                <include name="A.zip"/>
                <exclude name="B.zip"/>

Please advise how this could be achieved.


From the unzip task’s documentation:

Only file system based resource collections are supported by Unjar/Unwar/Unzip, this includes fileset, filelist, path, and files.

This means you have to have a physical copy of A.zip somewhere on the file system.

So, there really is no choice other than doing it in two steps:

<tempfile property="a" suffix=".zip"/>
<copy tofile="${a}">
    <zipentry zipfile="test.zip" name="A.zip"/>

<unzip src="${a}" dest="test_dir"/>
<delete file="${a}"/>

Source: stackoverflow