Link to home
Start Free TrialLog in
Avatar of laneway
lanewayFlag for Canada

asked on

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?
<target name="copy-dir">			
	<copy todir="./newdir">
		<fileset dir="./copyme"/>
	</copy>
</target>

Open in new window

Avatar of girionis
girionis
Flag of Greece image

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.

http://ant.apache.org/manual/CoreTasks/exec.html
Avatar of laneway

ASKER

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.
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?
Avatar of laneway

ASKER

I need this script to be cross platform. MacOs, Windows, Linux. Will the exec task work in that case?
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of laneway

ASKER

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.