Sunday, January 24, 2010

Maven Basics

Coming from the Ant world it took sometime for me to digest the basics of Maven and it is difficult to get into any tool or technology without getting its basics. So I am putting down my thoughts/understanding of maven for newbies.Also I request to point out and correct any mistakes as I am not an expert of Maven.

Why Maven and how is it different from Ant?
Maven is a standardized project development and lifecycle management system
for java projects.The problem with Ant was that each project will follow its own way of building and packaging applications and this lack of standard or convention will be a problem when switching from one project to another or sharing the libraries among projects.So a new concept of standardizing and building some patterns for different kind of projects came up which will help people to reuse the build models and libraries among projects.The basic concept of maven are described below.

1)Standard build structure
Maven enforces a standard build structure for all the java projects.Please refer the reference link to understand the same.

Reference :
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
2) Project Object Model or POM
Each project need to have an xml file(pom.xml) that contains information about the project and configuration details used by Maven to build the project.This should be placed in the root directory of the project.
Reference : http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

3) Concept of central repository for libraries
This is useful when you have multiple projects using the same set of libraries and want
to share them.Also it makes version control and dependancy management easy.The libraries will be made vailable in central repositories online and you specify the details of the libraries as dependencies in the pom.xml.You can find the libraries from either the central repository of maven ()or from any other Maven repositories available. When we build the system the the dependant jars will be downloaded from the net and will be put into your local
repository.You can specify the location of your local repository in M2_HOME/settings.xml or it will take a default location(For windows it is My Documents/.m2 and for linux ~home/.m2). So instead of each project maintaining separate libraries the libraries will be taken from the local repostory while building.The reference links have more information about repositories.

Reference:
http://maven.apache.org/guides/introduction/introduction-to-repositories.html
http://www.mkyong.com/maven/how-to-search-the-maven-coordinates-pom-xml-dependency/

4) Maven plugins and goals

Maven accomplishes everything using plugins .Intact Maven can be considered as a plugin
execution framework.We will crate a plugin for each task you want to do with maven.Each plugin will again have a set of goals.Maven comes with a standard set of plugins and goals for common project management tasks.
For eg.
clean -Clean up after the build.
site- Generate a site for the current project.

In addition to that you can create your own plugins to accomplish the tasks specific to your project.For eg.Scala has a maven plugin to help managing scala projects.Again plugin will be available in central repositories(http://repo1.maven.org/maven2/org/apache/maven/plugins for maven) .If you are using the libraries or plugins from maven central repository you need not specify the repositories and plugin repositories in pom.xml files.Any other repositories should be specified in pom.xml.

Reference :

http://maven.apache.org/plugins/index.html
http://hamandeggs.wordpress.com/2009/08/30/creating-a-simple-maven-plugin/

5) Maven archetype plugin

Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. Archetype will help authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.

To create a new project based on an Archetype, you need to call mvn archetype:generate goal as follows

mvn archetype:generate

It will list the archetypes available in the repositories available and you can choose the one which fits your project .It will ask for some more information about the project like name and version and once you provide those details archtype lugin will create the ptoject structure and pom.xml file for your project.Refer the links for more information


References
http://www.mkyong.com/maven/how-to-create-a-project-with-maven-template/
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html

Sunday, January 17, 2010

Believe me, Linux is as easy as any other OS

I recently read an article in computer world “You don't need to 'know' Linux to use Linux”.It addresses the notion people have that you need to master some commands or need some expertise to use linux easily. I can see people still have those notions even after linux as OS matured a lot and came a longway to compete with others. Let me adress some of them and i will be relying mainly the most popular desktop linux distro Ubuntu to prove my points.

  1. Installing linux may corrupt my windows OS

This might be mostly due to the fact that linux is following a different file system(ext3 or ext4) and the experience they might had in trying linx years before. In reality it is very strightforward and there is nothing to fear if you follow the proper instructions. The good thing is Ubuntu have very good documentation to help you in everything. Please refer the section Dual-Booting Windows and Ubuntu in the Ubuntu userguide.
  1. You need to know shell commands to use linux

This is very well addressed in the article I refered earlier(“You don't need to 'know' Linux to use Linux”.)

  1. Linux don't have good support for audio and video and you need to be hacker to make it work

This is a thing of the past and now all the popular disto's have support for all the popular audio and video file formats. But not all the drivers might not be bundled with the os as you might have for windows . If you take Ubuntu for example mp3 driver won't come bundled with Ubuntu as it is not complaint with Ubuntu license terms.You have to understand Ubuntu and open source philisophy to understand its reason fully ,but as normal user you just need to install gstreamer plugins separately from Ubuntu software center .I will be expalining installing applications in Ubuntu separately.


  1. I will be landed in strange world with none of favourite apps in windows not available.

You are right in one way as you might be using some windows software for years and is quiet confortable with them. But the point is that you have an alternate software of almost every kind in linux and there are many far better and lightweight than in windows. If you are determined it won't take much time learn any of them and you can see a lot more variety in linux world then you see in windows. For a list of applications refer the following links.

Ubuntu user guide

19 cool things to do after installing Ubuntu

http://blog.thesilentnumber.me/2009/09/top-things-to-do-after-installing.html


  1. It has a lot of security restrictions and is difficult to deal with

This is because linux is following unix architecture and is designed as a multiuser system at its core. This is basically different from the windows which was deveolped for desktop PC's. But linux architecture has a lot of advantages and is the reason why linux is considered the most secured os and have very less chance for the viruses to be affected. It may be annoying initially as there may be restrictions for normal users and once you understand it you will see the benefit.

  1. Installing applications is a painfull task and you need to be a techie to do that.

This is really wrong and ideally there is hardly any difference with windows now.Infact it is much easy as Ubuntu has a Ubuntu software center from you can find the applications and do a click and install. Fundamentally there is a difference in the way applications are installed and managed linux as linux is following a different file system architecture. But now everything is possible through GUI and if you are techie of course command line will give you more power.
  1. No one knows linux to support me if there is a problem.

This is another wrong notion. It may be right as you won't be having many people around you who know linux as linux is less popular than windows. But if you look at online you get answers for all your problems. Infact as linux is a community driven os it is very easy to get help from community than from official documentation as in case of windows.
  1. Anything comes free of cost is not good or with less quality.

Some people have a general feeling that as free software with less quality. This may be because the think that as linux is developed by volunteers who are not resposible for bugs and software doesn't offer any official support .This is infact wrong and eventhough free software is developed by volunteers they also go through the same rigorous development and testing cycles that commercal softwares do. Infact as there are more involement from community it is possible that more people test it at early stages and more bugs are fixed before the release.Even you can get commercial support from any linux vendors like Redhat or Novell if you are ready to pay for that.

  1. Linux is less user-friendly compared to windows.

This might be true few years back as linux GUI's were not that developed and there were no GUI for some taks. But now if you look at most Linux distros the GUI is in par with windows and you may even feel more confortable working with linux as its interface much more simple and lightweight. You will ofcourse have an affinity towards a platform you are working for years and may take some time to get confortable with a new once. But as a person recently moved completely to Ubuntu i felt linux is muck easy to work with and intellectually satisfying for me being a programmer.


Thursday, January 7, 2010

Why I started learning Scala ?

Recently I started learning Scala language.I have been working on java for the past 4 years and is quite satisfied with it.I am also sure java is going to stay there for a long term against all the criticisms and hatred of those dynamic language advocates. Java gives me lot of confidence to take a problem or project as I am sure there will be a solution in java for everything. As a new comer it may be confusing as java gives you a lot of options and it is difficult to choose the right approach or solution ,but as you mature you enjoy the freedom and power it gives .It is especially because java's open source nature and availability of lot of open source libraries and frameworks. Look for example how many web frameworks you have in java.

Recently we saw emergence a lot of jvm languages which according to me strengthens the java language platform. The important among them are Jruby,Jython,Scala,Clojure and Groovy Jruby and Jython are JVM versions of Ruby and Python respectively ,which are two powerful dynamic languages. They helps lovers of those dynamic languages to stick to that platform and at the same time leverage the power of JVM,the most tested, trustworthy VM platform. Groovy ,Scala and Clojure are developed independantly and among them scala attracted me very much and I decided to learn scala .This is mainly because I felt any need of learning any of the dynamic languages in JVM as java gives me what I want and I am confident with that. But when looking at Scala I saw some interesting stuff and felt it is worth to learn that. I am listing down some of those features.

1) Functional programming
Scala support for functional programming attracted me .As of now I didn't think much about the style of programming I followed and the debate over Imperative or functional programming in scala groups pushed me to take a deep look at functional programming aspects. Scala being a multi-paradigm language leverage the power of both functional and imperative approaches.
2) Type inference
Scala is strongly typed language and at the same time it has something called type inference by which it infers the type of a variable and relieves most of the burden from programmer.
3) Actors
Actor is a more advanced way for parallel programming instead of using threads and locks which is very low level and difficult to use for programmers.
4) DSL support
DSL (Domain specific languages) are gaining popularity and scala offers a power full support with its parser library.

I will try publish detailed notes on each of these as I progress ,but the interesting point is
that it forced me two look deep at some basic concepts of programming which I consider very valuable as a programmer.