So far we have used Ant to build our projects.
But, as you might have noticed, the build.xml keeps growing as our project gets more complex. The dependencies increase, so do the tasks and inter-dependencies between tasks.
Furthermore, as we use different frameworks like Spring, Hibernate, etc - we need to modify web.xml and create configuration files specific to the frameworks.
All and all, for a real world project, maintaining the build.xml, web.xml and all the other configuration xmls and property files starts to become a complicated job in itself. Very soon it has its own domain knowledge and expertise. Things start to break as time goes by.
Maven is an attempt to make project setup easier. It does so by using convention over configuration.
How does this work?
Suppose Jack has already developed a project using certain frameworks. He has painfully created the dependencies, the build scripts, configured the web.xml; and all other configuration files. Everything works.
Now Jill want to start a new project, and she intends to use pretty much the same frameworks that Jack has already configured into his project.
If Jack and Jill use Maven, Jack can create an "archetype" (we will learn archetypes in detail later) and Jill can ask Maven to create a new project using Jack's archetype.
Maven will reproduce Jack's exact structure - directories, build file, web.xml, configurations, libraries, etc.
Jill will be good to go in seconds!
The point to note is that Jill has followed Jack's convention, thus she has little or no configuration to do herself.
There are several Maven archetypes already available online, and that makes it easy to start your own project.
Furthermore, Maven provides dependency management (just like Ivy) and plugins that you can use to customize your project. Of course, having customized your project, you can provide your own archetype so someone else can benefit from your work instantly.
Important: Maven is not Ant!
There is an endless confusion created by people who switch from Ant to Maven, and expect Maven to work like Ant. This is a false approach. Maven has its own model and in trying to make it do-what-Ant-does people shoot themselves in the foot.
To experience the full pleasure of working with Maven, it is best to understand Maven's paradigm of convention-over-configuration and drop Ant habits of having to (being able to) specify every little detail of the build process.
Maven works at a much higher level. You tell Maven I want to build a war, and it will do it without any further instructions from you. Trying to micro-manage a Maven build as if it was Ant will only serve to create frustrating problems!
Don't go there! Instead, try to understand and internalize Maven's philosophy - use archetypes, accept conventions and avoid having to do things yourself.
No comments:
Post a Comment