Thursday, March 6, 2008


Are you creating large projects? Do you see the building process it complicated? Do you have to repeat many steps each time you build your project? Have you thought of a way to do this in one step? Apache Ant (or simply called Ant) can do this for you.

So what is Ant? I quoted this definitions for you:
"Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles." [ accessed on March 6, 2008]
"Apache Ant is a software tool for automating software build processes. It is similar to make but is written in the Java language, requires the Java platform, and is best suited to building Java projects." [ accessed on March 6, 2008]

If you are using Eclipse, then you already have an Ant plugin installed with your Eclipse. Ant is based on an XML build file. Each Ant build file contains some targets and each target encapsulates one or more tasks. Ant has some built in tasks like javac, jar, exec... etc and you can also extend it using Java classes creating your own custom tasks.

Well, this post won't be a tutorial on how to use Ant or the structure of an Ant build file; But I am going to tell you about my experience with Ant, so you can see how powerful is it.

During my internship at Easy Dialog on summer 2007, I was asked -as a training- to create an Ant custom task that inserts the project build information (project name, build date, time, user name...etc) into a database. So, I defined a custom task and created a Java class that takes the information and store them into the database through JDBC. So, whenever this custom task is called by Ant during build, the project build info is stored in the database.

Another time while working in my graduation project, we needed to create a Signed Applet. To create the signed applet, we've to do many steps: Build the applet classes, Export the applet into a Jar file, and signing the Jar file using jarsigner tool. Fortunately, there is a built in Ant task for signing a Jar file. So, I created an Ant build file that contained three targets:
  1. A target for compiling the source files and getting the class files.
  2. A target for archiving the .class files into a Jar file. This target depends on the compilation target.
  3. A target for signing the Jar file, which depends on the second target.
With the third target set as the default one in the Ant build file, and using Eclipse, I can get the signed Jar file from the source code by just one button click! Do you see how easy is this? :)

If you want to learn more about Ant, just follow these links [accessed on March 6, 2008]:

No comments: