Archive for April, 2006

Build Automation #4 - Understanding the Ant script

The build.xml in the example that you downloaded in the previous post contains the Ant script. Lets go through it to understand the key elements of the Ant script. Ofcourse it is not necessary that the ant script should be in a file called build.xml. If it is named something else then you need to tell ant which file it is when you run ant. And there could be multiple ant scripts that could be linked as well. You can learn about it from the Ant manual. Open up the build.xml file in an editor.

The very first element in any ant script is the project element. The project element contains the following attributes.

name - Name of the project
default - Default target to execute.
basedir - Which directory in the system should be taken as the base directory. If not provided the current directory from where Ant is executed will be treated as the base directory.

The below code is from our HelloWorld sample.

<project name="Hello World" default="package" basedir=".">

Ant basically works with targets. A target is a specific goal to be attained. A target contains set of tasks that needs to be executed in order to attain the goal. A target could dependent on one or more targets, in which case the dependent targets are executed first before this target gets executed. Lets take the clean target from our example.

<target name="clean" description="remove all ant generated files/folders">
<delete dir=”${target.dir}”/>
</target>

Of importance to us in the target element are three attributes - name, description and depends. The depends attribute holds other targets separated by commas that this target is dependent upon. In the above example, the clean target is not dependent on any other target. Within the target element you write all the tasks necessary to complete that target. A task could be a built in task or custom written. A task is a finite piece of code that can be executed. In the above example the clean target has one task which is delete. The delete task is a built in Ant task and its purpose is to delete files/folders in the system. Essentially the clean target’s goal is to clean up previous build artifacts. In our simple example, the target folder under the HelloWorld is where all the compiled classes and the final HelloWorld.jar gets placed. So basically the clean target aims at removing the target folder.

The delete target in our example has an attribute dir. Note the value we pass to the dir attribute. In Ant anything represented within ${} is treated as a variable and gets replaced with the value when the script executes. In our case target.dir is a property that we have defined in the beginning of the script.

<property name="target.dir" value="${basedir}/target"/>

A property is like declaring a variable. You could also put all your properties in a property file and refer the property file like,

<property file="build.properties"/>

and the build.properties containing the following.

src.dir=${basedir}/src
test.dir=${basedir}/test
lib.dir=${basedir}/lib
target.dir=${basedir}/target
classes.dir=${target.dir}/classes

Note that since it is a property file we define a property in property-name=property format.

With this information in mind, I am sure you would be able to understand the entire build script. Now the target dependency needs some more explanation. So when we call ant, what is the sequence in which the build is executed. Remember in our project element we gave the default target to be package. And if you look at the package target, it is dependent on unit-test target. If you tailgate behind the dependent targets, you would see this leads to the clean target in the following order.

package -> unit-test -> build -> create -> clean

So the execution begins from a target that is independent of any other target. So the execution of the targets would be like below.

clean -> create -> build -> unit-test -> package

It is always not necessary that you have to run the default target, you can tell ant to execute a specific target but just giving the target name when executing. Say for example I just want to compile the classes, then I give the following command.

c:\HelloWorld\>ant build

In this case ant focuses on the build target, tracks the dependent targets and executes them like below.

clean -> create -> build

In our case the target execution was simple and each target was dependent on only one target, but what if a target is dependent on more than one target. What will be the sequence in that case? Well go through the ant manual here to understand about it.

Blink this Build Automation #4 - Understanding the Ant script at blinklist.com    Bookmark Build Automation #4 - Understanding the Ant script at blogmarks    Bookmark Build Automation #4 - Understanding the Ant script at del.icio.us    Digg Build Automation #4 - Understanding the Ant script at Digg.com    Fark Build Automation #4 - Understanding the Ant script at Fark.com    Bookmark Build Automation #4 - Understanding the Ant script at Furl.net    Bookmark Build Automation #4 - Understanding the Ant script at NewsVine    Bookmark Build Automation #4 - Understanding the Ant script at reddit.com    Bookmark Build Automation #4 - Understanding the Ant script at Simpy.com    Bookmark Build Automation #4 - Understanding the Ant script at Spurl.net    Bookmark Build Automation #4 - Understanding the Ant script with wists    Bookmark Build Automation #4 - Understanding the Ant script at YahooMyWeb

Comments      Cosmos

Build Automation #3 - Ant in action

We will execute a simple Ant script today. While most of what I am going to present in this post and the next post is just an eye opener to Ant, you can get much in depth details, examples and tutorials by Googling around. The example in this post and the coming post(s) assume that you know Java. Download this small project that has the source and ant script file to package a Hello World program. The default distribution type for any java application is a java archive file, so we are going to build that. To execute the script you need to download Ant and configure it. Once you have set it up, go to DOS prompt and type the following command.

ant -version

If you have setup Ant correctly, you should be seeing an output something like this.

Apache Ant version 1.6.5 compiled on June 2 2005

This example runs unit tests using JUnit, so once you extract the zip file, create a folder called lib and copy the junit-3.8.1.jar into the lib folder (for want of space I removed it from the zip). This step is important, otherwise the build will fail.Once you have completed the above steps, assuming you have extracted the project under c:\HelloWorld, at the HelloWorld folder in the DOS prompt execute,

c:\HelloWorld\>ant

If you installed and configured everything correct you should see a successful build. Goto the target folder and see if HelloWorld.jar file is there. To make sure you can execute the HelloWorld application from the jar, execute the following command.

c:\HelloWorld\target\>java -cp .\HelloWorld.jar com.compassites.HelloWorld

Now with this basic script, you can keep adding your source file and with one command you can package all your source into a jar that you can distribute. We will look into the build.xml and understand the script in the next post.

Blink this Build Automation #3 - Ant in action at blinklist.com    Bookmark Build Automation #3 - Ant in action at blogmarks    Bookmark Build Automation #3 - Ant in action at del.icio.us    Digg Build Automation #3 - Ant in action at Digg.com    Fark Build Automation #3 - Ant in action at Fark.com    Bookmark Build Automation #3 - Ant in action at Furl.net    Bookmark Build Automation #3 - Ant in action at NewsVine    Bookmark Build Automation #3 - Ant in action at reddit.com    Bookmark Build Automation #3 - Ant in action at Simpy.com    Bookmark Build Automation #3 - Ant in action at Spurl.net    Bookmark Build Automation #3 - Ant in action with wists    Bookmark Build Automation #3 - Ant in action at YahooMyWeb

Comments      Cosmos

Build Automation #2 - Tools for build automation

Yesterday we saw a list of steps related to build and realized that automation could save a lot of time. But to enable automation we need some tool that can understand our requirement and carry it out whenever we want it to or on a schedule basis. So let’s take a look at some of the technologies that can help build automation. I am taking three of the popular technology environments here.

  • Java/J2EE
  • Ant - a powerful and widely used tool for build automation in the java/j2ee arena. Ant basically works by having tasks and executing them in the order specified. The tool is triggered with a target and ant executes the dependent targets and tasks associated with that target. ANT scripts are xml based and are easy to understand and write.
  • Maven - Maven is a software management and comprehension tool that works with the primary concept of project object model (pom). The pom represents the components , artifacts required by the project and its dependencies. Basically it contains everything about your project. The POM is the core and there are numerous plugins that can integrate with maven and can take care of lot of tasks other than just build and deployment.
  • CruiseControl - CruiseControl helps schedule build that are written in ANT or Maven and execute them and publish the result.
  • .Net
  • NAnt - Similar to NAnt, but for .Net environment
  • CruiseControl .Net - Similar to CruiseControl but for .Net environment
  • Ruby on Rails
  • Capistrano (earlier called SwitchTower) - Ruby on Rails continues to make life simpler and easier with powerful plugins such as Capistrano. Highlight is using them and starting to work with them is as simpler and easier just like starting to working on ROR. You can have your build and deployment automated in a jiffy.

Blink this Build Automation #2 - Tools for build automation at blinklist.com    Bookmark Build Automation #2 - Tools for build automation at blogmarks    Bookmark Build Automation #2 - Tools for build automation at del.icio.us    Digg Build Automation #2 - Tools for build automation at Digg.com    Fark Build Automation #2 - Tools for build automation at Fark.com    Bookmark Build Automation #2 - Tools for build automation at Furl.net    Bookmark Build Automation #2 - Tools for build automation at NewsVine    Bookmark Build Automation #2 - Tools for build automation at reddit.com    Bookmark Build Automation #2 - Tools for build automation at Simpy.com    Bookmark Build Automation #2 - Tools for build automation at Spurl.net    Bookmark Build Automation #2 - Tools for build automation with wists    Bookmark Build Automation #2 - Tools for build automation at YahooMyWeb

Comments      Cosmos

Personal Branding for Technology Professionals

My friend and mentor Rajesh Setty has published an e-book on “Personal Branding for Technology Professionals“. Wonderful book and the message is clear. The value of a pearl is realized only when it is taken out from the oyster shell and used. What differentiates extraordinary from ordinary is that extra. However technically strong you are, if you don’t brand yourself properly in this competitive world and showcase that extra in you to this world, you are still ordinary.

It is a privilege for us to sponsor such a wonderful e-book and make it available free for everyone. Here is an additional bonus. Listen to Rajesh speak on “Personal Branding” in the popular podcast network show, “The Cranky Middle Manager” by Wayne Turmel.

Blink this Personal Branding for Technology Professionals at blinklist.com    Bookmark Personal Branding for Technology Professionals at blogmarks    Bookmark Personal Branding for Technology Professionals at del.icio.us    Digg Personal Branding for Technology Professionals at Digg.com    Fark Personal Branding for Technology Professionals at Fark.com    Bookmark Personal Branding for Technology Professionals at Furl.net    Bookmark Personal Branding for Technology Professionals at NewsVine    Bookmark Personal Branding for Technology Professionals at reddit.com    Bookmark Personal Branding for Technology Professionals at Simpy.com    Bookmark Personal Branding for Technology Professionals at Spurl.net    Bookmark Personal Branding for Technology Professionals with wists    Bookmark Personal Branding for Technology Professionals at YahooMyWeb

Comments      Cosmos

Build Automation #1 - What is it all about?

Some of my friends told me after reading my yesterday’s post that it went above their head. Particularly on automation. So let me start introducing build automation. In any project there are certain mundane tasks that get repeated over and over again. One of them is doing a build and deployment of your application. First lets list out what are the steps to be performed when you are ready to build an application for deployment or distribution.

  1. Get the latest checked in code from version control system
  2. Compile the code
  3. Optionally make changes to certain configuration/property files to reflect your target environment
  4. Package the compiled code and other resource files in the structure required
  5. Distribute and/or deploy the packaged application

The above are the minimal number of steps that is required in any typical build process. Now think about this. Does any of the above step got anything to do with the actual project itself? Not really, whatever be the project you got to go through the above process, only the parameters are going to change like for example from which project folder you want to get from the version control and so on. Typically, if not hosting/deploying your application on a production environment, you ought to do build to do integration test in your development, QA and stage environments. Even if your project follows a waterfall methodology you would do a build quite a number of times atleast to do the integration test. Think about the amount of effort you may have to do if you are going to follow the above steps manually. Build automation is all about automating the above steps (and more as necessary). A click of a button or a simple command execution would result in the deployment of your latest code. We will dwelve more into it in the coming posts.

Blink this Build Automation #1 - What is it all about? at blinklist.com    Bookmark Build Automation #1 - What is it all about? at blogmarks    Bookmark Build Automation #1 - What is it all about? at del.icio.us    Digg Build Automation #1 - What is it all about? at Digg.com    Fark Build Automation #1 - What is it all about? at Fark.com    Bookmark Build Automation #1 - What is it all about? at Furl.net    Bookmark Build Automation #1 - What is it all about? at NewsVine    Bookmark Build Automation #1 - What is it all about? at reddit.com    Bookmark Build Automation #1 - What is it all about? at Simpy.com    Bookmark Build Automation #1 - What is it all about? at Spurl.net    Bookmark Build Automation #1 - What is it all about? with wists    Bookmark Build Automation #1 - What is it all about? at YahooMyWeb

Comments      Cosmos

Attribute oriented programming using XDoclet

XDoclet is a open source code generation engine for java/j2ee. Why do you need a source code engine? Think about this, in the project that you are working, how much percentage of code that you have written is not related to the problem domain but related to the technology that you have selected? Take EJB as an example. If you want to write an EJB you need to have a remote interface and a home interface and you need to have the ejb.xml and the JNDI properly configured. What if I had a way to generate the necessary XML artifacts before I compile and package the application?
Welcome XDoclet. XDoclet adds on top of your javadoc, certain meta data (attributes) which is processed by XDoclet engine and replaced/added and/or modified with whatever is needed. So if you put in the include the XDoclet tag in your javadoc comment, you just need to focus on coding the domain objects or code that is required to meet a requirement and leave the rest to XDoclet to generate technology specific code/XML artifiacts before compilation/packaging. Ant plays an excellent catalyst here to enable this process smooth. But XDoclet does not support all the technologies and all feature/function set in a technology. You can find list of technologies that is supported in the XDoclet site. Ant is an open source tool to automate the build and deployment process for java/j2ee applications. We will look at more of build and deployment automation in the coming days. Also look at XDoclet2 from CodeHaus for additional plugins and extensions.

Blink this Attribute oriented programming using XDoclet at blinklist.com    Bookmark Attribute oriented programming using XDoclet at blogmarks    Bookmark Attribute oriented programming using XDoclet at del.icio.us    Digg Attribute oriented programming using XDoclet at Digg.com    Fark Attribute oriented programming using XDoclet at Fark.com    Bookmark Attribute oriented programming using XDoclet at Furl.net    Bookmark Attribute oriented programming using XDoclet at NewsVine    Bookmark Attribute oriented programming using XDoclet at reddit.com    Bookmark Attribute oriented programming using XDoclet at Simpy.com    Bookmark Attribute oriented programming using XDoclet at Spurl.net    Bookmark Attribute oriented programming using XDoclet with wists    Bookmark Attribute oriented programming using XDoclet at YahooMyWeb

Comments      Cosmos

The process of software architecting

It is usually a common debate on the topic of describing software architecture. The common questions that come up are,

  1. What is architecture?
  2. What is the software architecting process?
  3. What is the scope of architecture in the overall development of a project?
  4. When does it start and where does it end?
  5. Is architecture a science or an art?

Here is an article in IBM developerWorks by Peter Eeles on the process of software architecting. And here is the follow-up summary of the same article in Artima by Frank Sommers.

Blink this The process of software architecting at blinklist.com    Bookmark The process of software architecting at blogmarks    Bookmark The process of software architecting at del.icio.us    Digg The process of software architecting at Digg.com    Fark The process of software architecting at Fark.com    Bookmark The process of software architecting at Furl.net    Bookmark The process of software architecting at NewsVine    Bookmark The process of software architecting at reddit.com    Bookmark The process of software architecting at Simpy.com    Bookmark The process of software architecting at Spurl.net    Bookmark The process of software architecting with wists    Bookmark The process of software architecting at YahooMyWeb

Comments      Cosmos

Why the name Bluetooth?

You must have heard of Bluetooth or most probably be using it by all means by now. Did you ever think why the concept was named Bluetooth? Well here is a snippet from Wikipedia on Bluetooth as to why it was named so.

The name Bluetooth was born from the 10th century king of Denmark, King Harold Bluetooth (whose surname is sometimes written as Bluetooh), who engaged in diplomacy which led warring parties to negotiate with each other. The inventors of the Bluetooth technology thought this a fitting name for their technology which allowed different devices to talk to each other.

Have a great week ahead.

Blink this Why the name Bluetooth? at blinklist.com    Bookmark Why the name Bluetooth? at blogmarks    Bookmark Why the name Bluetooth? at del.icio.us    Digg Why the name Bluetooth? at Digg.com    Fark Why the name Bluetooth? at Fark.com    Bookmark Why the name Bluetooth? at Furl.net    Bookmark Why the name Bluetooth? at NewsVine    Bookmark Why the name Bluetooth? at reddit.com    Bookmark Why the name Bluetooth? at Simpy.com    Bookmark Why the name Bluetooth? at Spurl.net    Bookmark Why the name Bluetooth? with wists    Bookmark Why the name Bluetooth? at YahooMyWeb

Comments      Cosmos

· « Previous entries

Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.