How do I quickly copy a directory using Apache Ant?
I am trying to duplicate a directory using apache ant and the copy task. When I use my OS to duplicate the directory, it takes about 30 seconds. When I use the ant copy task (as shown below) it takes 4 minutes and 30 seconds! Is there a faster way?
It shouldn't take so long. Do you only copy the files or you execute other tasks as well? If all alse fails you can try to exec task, which calls an external process. So you could call the copy command and copy the files using the native processes.
I am not doing anything else, the wait time comes from here. It seems to be copying the contents of the directory file by file rather than by the whole directory.
Is it possible that it is excluding some files or applying a pattern without me knowing it?
Interestingly if I use the old copydir task, it takes 2 minutes and 30 seconds instead of 4 minutes and 30 seconds...
I don't get it.
girionis
I am not sure what is going on behind the hood. Maybe it has to do other things before it can copy all the files. And it's possible that it's using Java to do it, so it has to load up all the necessary classes and then do a copy. Have you tried using the exec task?
I am convinced that the exec task method will work, though it is not as elegant as I had hoped. I suspect that either ANT is just slow or there is some other non-obvious reason why it is behaving the way it does on my system.
http://ant.apache.org/manual/CoreTasks/exec.html