Deploying Applications
As you'd expect, Ant excels at deploying applications, and there
are a number of tasks to choose from. You've saw the javac task's destdir attribute for deployment back in Chapter 1. In this section, you'll see
copy, move, ftp,
telnet, and sshexec.
The copy and move tasks are useful for local and network
deployments, and tasks like ftp are
great for remote deployments. Additionally, Chapter 8 will cover deployment to web
servers with tasks like get, which
you can use to send administrative commands to servers like Tomcat (I'll
cover Tomcat's built-in custom Ant tasks), and serverdeploy.
Tip
Want to get a file's name without the path attached? Pass the
filename to the basename task. Want
to get just the path? Use dirname.
The pathconvert task converts a
nested path or reference to a Path,
FileSet, DirSet, or FileList into a path (automatically adjusted for
the target platform) and stores the result in a given property.
Deploying by Copying
This task copies a file, or a fileset, to a new file or a new directory. This is Ant's most basic deployment task for local and network deployment. Here are a few examples, starting with copying just one file:
<copy file="file.txt" tofile="backup.txt"/>
This example copies a file to a new location:
<copy file="file.txt" todir="../backup"/>
This example copies an entire directory to a new location:
<copy todir="../backup">
<fileset dir="${src}"/>
</copy>This copies a set of files to a new directory:
<copy todir="../backup"> ...