Automating build process with apache ant

Why and what is Ant?

Without using ant, building and deploying web applications and other enterprise applications required a series of scripts or manual processes, which often led to mistakes.

Apache ant is a powerful tool for automating software build processes. It is implemented by Apache Foundation using java language, requires the java platform and is best suited for building java projects. However that doesn’t means it restricted to java projects. Dot net project also can use ant to automate the build process (Nant). Ant makes application building process and releasing them across different servers far more efficient and less problematic. Ant is applicable for most integrated development environment (IDE) that uses java.

Ant uses XML to describe the build process and its dependencies. By default the xml file named as build.xml. This makes it really simple for you setup and edit different build processes. Build files in ant are extremely important in a project, must be written in care, and maintain in version control and re-factored periodically, when the project dependencies change.

Best features of Ant technology.

Ant is a powerful, platform independent, open source tool. If you choose to use it, get it to do absolutely everything. Ant can integrate with your source control database such as SVN or SCM, run SQL scripts, change file permissions, Send file across FTP, Zip and Unzip files, compile java files, create jar files, and many more tasks beside this.

The best features of the ant technology can be summarized as below:

Easy to Use: It is not a programming language, based on xml and easy to understand and implement.
Portable and cross platform based: Ant is implemented using java and it makes portable. i.e., it can be run on any platform.
Extended functionality: Ant’s functionality can be extended to any development environment based on java.
Build automation: Ant provides automated build process that is faster and more efficient.
Compilation of source code: Ant can compile source code from a variety of version controls and packaging of the compiled code and resources can also be done.

Ant expects your build file to be called build.xml and builds properties file These files also should be in the root directory of your project. Spend the time to formatting the build file. Since XML is quite verbose, use tabs and line breaks to make the file readable to the human eye. Ant itself does not care if the file looks pretty. But you can bet that you and your team will.

Installing ant on the desktop:

The current version (1.7.1) of ant was released on 27-jun-2008 and it can be downloaded on They are provided many formats (zip, tar etc) and you can download any one from there. I’m explaining how to install ant from zip file here. After complete downloading, unzip the content to the C directory. The path for the ant will be “C:\apache-ant-1.7.0”. Then we have to set some environment variables to get ant to work. Right-click on the “MyComputer” and select “properties”. GF to “Advanced” tab and click on “Environment Variables”. Under environment variables, you have to set following path variables.
Set value “C:\apache-ant-1.7.0” to ANT_HOME variable
Set value “C:\apache-ant-1.7.0\lib” to CLASS_PATH variable
Set value “C:\Java\jdk1.5.0_15” to JAVA_HOME variable
Set value “C:\apache-ant-1.7.0\bin” to PATH variable

That is all you have to do for installing ant. Now you have to check whether the installation process is done properly or not. To do this open the command prompt and run the command C:\>ant (just type ant and hit enter). If the following message is appears, then it indicate that your installation is successful. Ant is properly installed on your system.

Why Hibernate instead of direct JDBC ?

Hibernate is a powerful, high performance Object/Relational persistance and query service for both Java and .Net. Hibernate provides the bridge between the database and the application by storing application objects in the database for the developer, rather than requiring the developer to write and maintain mountains of code to store and retrieve objects.

Using a JDBC connection you’ll be unable to store objects directly to the database-you must convert the objects to a relational format. If we consider a domain class called Event, and if you want to persist a new instance of the Event class to the database, you must first convert the Event object to a SQL statement that can be executed on the underlying database. Similarly, when rows are returned from the database, you must convert each result row into an instance of Event.

When working with objects, you are generally using a number of connected objects. This is called as an object graph. An object graph represent an internally consistent view of application data. Internally consistence means that a change made to one object is reflected throughout the graph. The objects within a graph are typically connected using one-to-one or one-to-many associations.

Using direct JDBC for persistence presents distinct problems for each of the persistence operations: creation, updating, retrieval, and deletion.

Hibernate addresses all the shortcomings of the persistence techniques using direct JDBC and offers a number of additional features. Using Hibernate doesn’t require that your domain objects implement specific interface or use an application server. It supports collections, inheritance, and custom data types, as well as a rich query language.