Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Introduction to Apache Maven 2

Sing Li (westmakaha@yahoo.com), Author, Wrox Press
Photo of Sing Li
Sing Li is a consultant and an active author with more than two decades of industry experience. He has contributed to Professional Apache Geronimo, Beginning JavaServer Pages, Professional Apache Tomcat 5, Pro JSP - Third Edition, Early Adopter JXTA, Professional Jini, Beginning J2ME: From Novice to Professional, Third Edition, Professional Apache Geronimo, and numerous other books. Sing also writes for technical magazines and participates in open source communities. He is an evangelist of the open source, VOIP, and P2P movements. You can reach Sing at westmakaha@yahoo.com.

Summary:  Modern software projects are no longer solely monolithic creations of single local project teams. With the increased availability of robust, enterprise-grade open source components, today's software projects require dynamic collaboration among project teams and often depend on a mix of globally created and maintained components. Now in its second generation, the Apache Maven build system -- unlike legacy build tools created before the Internet-enabled era of global software development -- was designed from the ground up to take on these modern challenges. This tutorial gets you started with Maven 2.

Date:  19 Dec 2006
Level:  Intermediate

Activity:  152623 views
Comments:  

Overview of Maven 2

Maven is a top-level open source Apache Software Foundation project, created originally to manage the complex build process of the Jakarta Turbine project. Since this humble beginning, development projects in both the open source and the private realm have embraced Maven as the project build system of choice. Rapidly evolving, and now in version 2, Maven has grown from a customized build tool for a single complex project to a generalized build management system with a cornucopia of features applicable to most software development scenarios.

In a nutshell, Maven 2:

  • Understands how a project is typically built.

  • Makes use of its built-in project knowledge to simplify and facilitate project builds.

  • Leverages its built-in project knowledge to help users understand a complex project's structure and potential variations in the build process.

  • Prescribes and enforces a proven dependency management system that is in tune with today's globalized and connected project teams.

  • Provides a simple and unintrusive user experience for simple projects, leveraging its internal knowledge.

  • Is completely flexible for power users; the built-in models can be overridden and adapted declaratively (via configuration, modification of metadata, or creation of custom plug-ins) for specific application scenarios.

  • Is fully extensible for scenario details not yet covered by existing behaviors.

  • Is continuously improved by capturing any newfound best practices and identified commonality between user communities and making them a part of Maven's built-in project knowledge.

Maven 2 -- A conceptual overview

To capture project-building knowledge, Maven 2 relies on an evolving set of conceptual models of how things should work. These models, partially hardcoded as part of the Maven 2 code base, are constantly refined through new Maven releases. Figure 1 illustrates the key Maven 2 models:


Figure 1. Maven 2 object and operation models
Maven 2 Object and operation models

The key components in Figure 1 are:

  • Project object model (POM): The POM is a cornerstone model for Maven 2. Part of this model is already built into the Maven engine (fondly called the reactor), and you provide other parts declaratively through an XML-based metadata file named pom.xml.

  • Dependency management model: Maven is particular about how project dependencies are managed. Dependency management is a gray area that typical build-management tools and systems choose not to be specific about. The Maven dependency management model is built into Maven 2 and can be adapted to most requirements. This model is a proven workable and productive model currently deployed by major open source projects.

  • Build life cycle and phases: Coupled to the POM are the notions of build life cycle and phases. This is Maven 2's interface between its built-in conceptual models and the real physical world. When you use Maven, work is performed exclusively via plug-ins. Maven 2 orchestrates these plug-ins, following a series of well-defined phases in a build cycle.

Don't worry if some of these concepts still seem a little fuzzy. The following sections provide concrete examples solidifying the concepts behind these models.


Maven 2 -- A physical overview

Figure 2 reveals the operation of and interactions with Maven 2, exposing its physical composition. Figure 2 provides you with a view of how you might interact with Maven 2:


Figure 2. Maven 2 operation and interaction model
Maven 2 operation and interaction model

In Figure 2, the POM is Maven's understanding of your particular project. This model is formed by declarative descriptions contained in a series of pom.xml files. The pom.xml files form a tree, and each can inherit attributes from its parent. Maven 2 provides a Super POM. The Super POM sits at the top the hierarchy tree and contains default common attributes for all projects; every project POM inherits from it.

Dependencies are specified as part of the pom.xml file. Maven resolves project dependencies according to its dependency management model. Maven 2 looks for dependent components (called artifacts in Maven terminology) in local and global repositories. Artifacts resolved in remote repositories are downloaded to the local repository for efficiency of subsequent access. The dependency resolver in Maven 2 can deal with transitive dependencies. That is, it works properly when resolving dependencies that your dependencies depend on.

The Maven engine itself performs almost all its file-handling tasks through plug-ins. Plug-ins are configured and described in the pom.xml file. The plug-ins themselves are handled as artifacts by the dependency management system and are downloaded on demand as they are needed for a build task. Each plug-in can be associated with the various phases of a life cycle. The Maven engine has a state machine that marches through the life-cycle phases and invokes plug-ins as necessary.

2 of 15 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology, Open source
ArticleID=184162
TutorialTitle=Introduction to Apache Maven 2
publish-date=12192006
author1-email=westmakaha@yahoo.com
author1-email-cc=