Search code examples
linuxantzip

Can not run ' Ant exec executable="zip" '


Below is my ant script.

<exec executable="zip" dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
    <arg value="-y"/>
    <arg value="-r"/>
    <arg value="${file.path}"/>
    <arg value="*"/>
  </exec>

But below error occur.


zip-image_binary:
     [exec]     zip warning: name not matched: *
     [exec]
     [exec] zip error: Nothing to do! (try: zip -y -r /usr/local/clo/ven/image/a.zip . -i *)
     [exec] Result: 12

My purpose is to zip all the files and directories under /usr/local/clo/ven/image/manual_bundle/testzip/


Solution

  • When you run the command using your shell then the shell expands the * glob pattern. The zip executable doesn't expect any pattern at all but a list of files (usually provided by your shell). If you don't want to use the built-in zip task you can emulate that behaviour by using apply rather than exec. Something like this

    <apply executable="zip" parallel="true" relative="true"
           dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
      <fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
      <mergemapper to="${file.path}"/>
      <arg value="-y"/>
      <arg value="-r"/>
      <targetfile/>
    </apply>
    

    The equivalent zip task is a lot simpler

    <zip destfile="${file.path}">
      <fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
    </zip>