How to create ZIP file properly using zipfileset?

2019-08-23 06:02发布

问题:

I want to gather all .map files from Myproj directory also from it's sub-directories, then create a L.zip file.

Here is my code.

<target name="buildLFiles" >    
  <zip destfile="../../bin/L.zip" update="true" >
     <zipfileset casesensitive="no" dir="../../../Myproj" includes= "****/*.MAP" />
  </zip>
</target>

Problem here is, I am getting all .map files but it is getting created in file hierarchy wise.

Example:

This is original file structure:

MyProj  
 |- a  
    |- b   
       | - x1.MAP  

Current Output:

L
|- a
   |- b 
      | - x1.MAP

Required output:

L
|- x1.MAP

回答1:

What you could do is flatten the structure using the copy task's flatten attribute in another directory, then zip that directory.

<target name="buildLFiles">
     <property name="tmp.dir" value="../../bin/TMP" />
     <property name="zip.file" value="../../bin/L.zip" />
     <copy todir="${tmp.dir}" flatten="true">
         <fileset dir="../../../Myproj">
             <include name="**/*.MAP" />
         </fileset>
     </copy>
     <zip destfile="${zip.file}" update="true">
         <zipfileset casesensitive="no" dir="${tmp.dir}" includes="*.MAP" />
     </zip>
     <delete dir="${tmp.dir}" />
</target>


标签: java ant