Ant for web developers
I just spent the last day configuring an apache ant script to automate some tasks in our development environment and I figured I would share some of what I learned.
If you are not familiar with Ant please take a look at apache’s documentation. In the past I have made heavy use of shell scripts in build procedures but since I am now primarily working in a Windows environment with co-workers who don’t know their $s and #s I thought it best to adopt something that can easily be used in our Eclipse IDE. You can pretty much do the same stuff except the syntax is in XML form and loops and logic statements aren’t as straight forward as writing if/then/else/fi.
One link I found that was a great deal of help was Julien Lecomte’s (Yahoo!) post on Building Web Applications With Apache Ant. Julien covers some best-practices such as pre-processing and compressing javascript files. In addition to his suggestions I also came up with a few more tricks that other might find useful. For example, for testing purposes many people may have a <base href=”http://localhost/” mce_href=”http://localhost/”/> tag in one or more files. Before you deploy these files to your server you will probably want to change them. This can be done with a very simple Ant task:
<replace file="header.inc" token="http://localhost/" value="http://www.huyler.net/"/>
Another tip is to automate clearing out the server and uploading all the new files from scratch. This ensures everything is up-to-date on the server and no lingering files are left behind.
<ftp server="www.huyler.net" action="del" remotedir="/path/to/folder" userid="wwwuser" password="wwwpass"> <fileset> <include name="*"/> </fileset></ftp> <ftp server="www.huyler.net" action="rmdir" remotedir="/path/to" userid="wwwuser" password="wwwpass"> <fileset> <include name="folder"/> </fileset></ftp> <ftp server="www.huyler.net" action="mkdir" chmod="0755" remotedir="/path/to/folder" userid="wwwuser" password="wwwpass"> </ftp> <ftp server="www.huyler.net" action="put" remotedir="/path/to/folder" userid="wwwuser" password="wwwpass"> <fileset dir="local/folder"> <include name="*"/> </fileset></ftp>
If you are having trouble getting the ftp command to work on Eclipse, take a look at Brandon Harper’s post on the topic.