Search code examples
macosantfile-copying

How to preserve exec file in ant copy task


I have created Java FX bundle for Mac OS X using Ant. It creating bundle with two files - 1. MyApplication.app 2. MyApplication.dmg

I wish to copy both files at other folder, so I wrote command in my build.xml as -

<copy todir="my_new_folder">
   <fileset dir="old_folder\bundles"/>
</copy>

It copying both files successfully at "my_new_folder". But on running .app from "my_new_folder" not launching my application though it is launching from "old_folder" correctly.

On comparing copied app I found that on exec (Unix Executable File) resided at MacOS folder ("Show Package Contents/Contents/MacOS") not preserving, its kind been changing in document file.

How to preserve its kind to Unix Executable File as I am simply executing simple copy directory.

Thanks, Neelam Sharma


Solution

  • As noted in the ant copy task guide:

    Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission-preserving copy function, use this instead:

    <exec executable="cp" ... >
    

    So, in your case, replace <copy> with:

    <exec executable="cp">
        <arg line="-R old_folder/bundles my_new_folder"/>
    </exec>
    

    (note that you should use forward slashes, even if this ant script is being used under Windows).