If you know the syntax of build.xml that Ant expects, you can skip this sections. For those of you who have not worked with Ant before, let me explain. An Ant build file is usually called build.xml and is an XML file that has its top node <project> that describes your project. In the project you can defined name, basedir and default target.
Next, you define all your targets. A target is a subset of tasks that might depend on another subset or be completely independent. In the example above I have two targets: clean and build. The build one (which is also the default one) will create a BUILD directory, the second one - clean - will delete it. Besides that tasks do not do anything else. The build target depends on clean, which means if you execute build target, it will first execute the clean target, making sure that the BUILD directory is recreated each time you build.
To execute you target type "ant target-name" in the console. Or just "ant" if you want to execute the default target.
Let me walk through the changes. First of all, I concatenate all files with contact task, which is a standard task with Ant in lines 12-14.
Then I minify all.js with JSMIN task, which is not part of Ant installation, and you will need to download
the .jar file and put it in Ant jar directory. I define the custom task in line 3 and do actual minification in
lines 16-19. Here is a quick link for you for JSMIN .tar file,
which you will need to put into
if you are on a Max OS X 10.7.5 (Lion) or the appropriate folder for you OS.
Finally, your project is ready to be deployed into the development server. To do this, we are going to tar only the necessary files, upload it with SCP and deploying on the remove server.
In lines 27-32 I create a tar of my project excluding files that I do not need on my server, namely my BUILD folder and the build.xml file. Then I zip it up with gzip in line 33 and in lines 37-47 I upload it to the destination server, which is defined in lines 3-5 and securely ask user to enter the password. And finally, I remotely execute my ssh command to unpack the archive into the right place.
That's pretty cool. My entire process is only 25 seconds, it does all for me automatically and there is no room for human error. Besides, I can teach anyone how to do this without a problem.