You are previewing Maven: The Definitive Guide.
O'Reilly logo
Maven: The Definitive Guide

Book Description

For too long, developers have worked on disorganized application projects, where every part seemed to have its own build system, and no common repository existed for information about the state of the project. Now there's help. The long-awaited official documentation to Maven is here. Written by Maven creator Jason Van Zyl and his team at Sonatype, Maven: The Definitive Guide clearly explains how this tool can bring order to your software development projects. Maven is largely replacing Ant as the build tool of choice for large open source Java projects because, unlike Ant, Maven is also a project management tool that can run reports, generate a project website, and facilitate communication among members of a working team. To use Maven, everything you need to know is in this guide. The first part demonstrates the tool's capabilities through the development, from ideation to deployment, of several sample applications -- a simple software development project, a simple web application, a multi-module project, and a multi-module enterprise project. The second part offers a complete reference guide that includes:

  • The POM and Project Relationships

  • The Build Lifecycle

  • Plugins

  • Project website generation

  • Advanced site generation

  • Reporting

  • Properties

  • Build Profiles

  • The Maven Repository

  • Team Collaboration

  • Writing Plugins

  • IDEs such as Eclipse, IntelliJ, ands NetBeans

  • Using and creating assemblies

  • Developing with Maven Archetypes

Several sources for Maven have appeared online for some time, but nothing served as an introduction and comprehensive reference guide to this tool -- until now. Maven: The Definitive Guide is the ideal book to help you manage development projects for software, web applications, and enterprise applications. And it comes straight from the source.

Table of Contents

  1. Maven: The Definitive Guide
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Preface
      1. Maven... What Is It?
      2. Font Conventions
      3. Maven Writing Conventions
      4. Using Code Examples
      5. Safari® Books Online
      6. How to Contact Us
      7. Acknowledgments
    4. I. Introduction
      1. 1. Introducing Apache Maven
        1. Convention over Configuration
        2. A Common Interface
        3. Universal Reuse Through Maven Plugins
        4. Conceptual Model of a “Project”
        5. Is Maven an Alternative to XYZ?
        6. Comparing Maven and Ant
        7. Summary
      2. 2. Installing and Running Maven
        1. Verify Your Java Installation
        2. Downloading Maven
        3. Installing Maven
          1. Installing Maven on Mac OS X
          2. Installing Maven on Microsoft Windows
          3. Installing Maven on Linux
          4. Installing Maven on FreeBSD or OpenBSD
        4. Testing a Maven Installation
        5. Maven Installation Details
          1. User-Specific Configuration and Repository
          2. Upgrading a Maven Installation
        6. Getting Help with Maven
        7. Using the Maven Help Plugin
          1. Describing a Maven Plugin
        8. About the Apache Software License
    5. II. Maven by Example
      1. 3. A Simple Maven Project
        1. Introduction
          1. Downloading This Chapter’s Example
        2. Creating a Simple Project
        3. Building a Simple Project
        4. Simple Project Object Model
        5. Core Concepts
          1. Maven Plugins and Goals
          2. Maven Lifecycle
          3. Maven Coordinates
          4. Maven Repositories
          5. Maven’s Dependency Management
          6. Site Generation and Reporting
        6. Summary
      2. 4. Customizing a Maven Project
        1. Introduction
          1. Downloading This Chapter’s Example
        2. Defining the Simple Weather Project
          1. Yahoo! Weather RSS
        3. Creating the Simple Weather Project
        4. Customize Project Information
        5. Add New Dependencies
        6. Simple Weather Source Code
        7. Add Resources
        8. Running the Simple Weather Program
          1. The Maven Exec Plugin
          2. Exploring Your Project Dependencies
        9. Writing Unit Tests
        10. Adding Test-Scoped Dependencies
        11. Adding Unit Test Resources
        12. Executing Unit Tests
          1. Ignoring Test Failures
          2. Skipping Unit Tests
        13. Building a Packaged Command-Line Application
      3. 5. A Simple Web Application
        1. Introduction
          1. Downloading This Chapter’s Example
        2. Defining the Simple Web Application
        3. Creating the Simple Web Project
        4. Configuring the Jetty Plugin
        5. Adding a Simple Servlet
        6. Adding J2EE Dependencies
        7. Conclusion
      4. 6. A Multimodule Project
        1. Introduction
          1. Downloading This Chapter’s Example
        2. The Simple Parent Project
        3. The Simple Weather Module
        4. The Simple Web Application Module
        5. Building the Multimodule Project
        6. Running the Web Application
      5. 7. Multimodule Enterprise Project
        1. Introduction
          1. Downloading This Chapter’s Example
          2. Multimodule Enterprise Project
          3. Technology Used in This Example
        2. The Simple Parent Project
        3. The Simple Model Module
        4. The Simple Weather Module
        5. The Simple Persist Module
        6. The Simple Web Application Module
        7. Running the Web Application
        8. The simple-command Module
        9. Running simple-command
        10. Conclusion
          1. Programming to Interface Projects
    6. III. Maven Reference
      1. 8. Optimizing and Refactoring POMs
        1. Introduction
        2. POM Cleanup
        3. Optimizing Dependencies
        4. Optimizing Plugins
        5. Optimizing with the Maven Dependency Plugin
        6. Final POMs
        7. Conclusion
      2. 9. The Project Object Model
        1. Introduction
        2. The POM
          1. The Super POM
          2. The Simplest POM
          3. The Effective POM
          4. Real POMs
        3. POM Syntax
          1. Project Versions
            1. Version build numbers
            2. SNAPSHOT versions
          2. Property References
        4. Project Dependencies
          1. Dependency Scope
          2. Optional Dependencies
          3. Dependency Version Ranges
          4. Transitive Dependencies
            1. Transitive dependencies and scope
          5. Conflict Resolution
          6. Dependency Management
        5. Project Relationships
          1. More on Coordinates
          2. Multimodule Projects
          3. Project Inheritance
        6. POM Best Practices
          1. Grouping Dependencies
          2. Multimodule Versus Inheritance
            1. Simple project
            2. Multimodule enterprise project
            3. Prototype parent projects
      3. 10. The Build Lifecycle
        1. Introduction
          1. Clean Lifecycle (clean)
          2. Default Lifecycle (default)
          3. Site Lifecycle (site)
        2. Package-Specific Lifecycles
          1. JAR
          2. POM
          3. Maven Plugin
          4. EJB
          5. WAR
          6. EAR
          7. Other Packaging Types
        3. Common Lifecycle Goals
          1. Process Resources
          2. Compile
          3. Process Test Resources
          4. Test Compile
          5. Test
          6. Install
          7. Deploy
      4. 11. Build Profiles
        1. What Are They For?
          1. What Is Build Portability?
            1. Nonportable builds
            2. Environment portability
            3. Organizational (in-house) portability
            4. Wide (universal) portability
          2. Selecting an Appropriate Level of Portability
        2. Portability Through Maven Profiles
          1. Overriding a Project Object Model
        3. Profile Activation
          1. Activation Configuration
          2. Activation by the Absence of a Property
        4. External Profiles
        5. Settings Profiles
          1. Global Settings Profiles
        6. Listing Active Profiles
        7. Tips and Tricks
          1. Common Environments
          2. Protecting Secrets
          3. Platform Classifiers
        8. Summary
      5. 12. Maven Assemblies
        1. Introduction
        2. Assembly Basics
          1. Predefined Assembly Descriptors
          2. Building an Assembly
          3. Assemblies as Dependencies
          4. Assembling Assemblies via Assembly Dependencies
        3. Overview of the Assembly Descriptor
        4. The Assembly Descriptor
          1. Property References in Assembly Descriptors
          2. Required Assembly Information
        5. Controlling the Contents of an Assembly
          1. Files Section
          2. fileSets Section
          3. Default Exclusion Patterns for fileSets
          4. dependencySets Section
            1. Customizing dependency output location
            2. Interpolation of properties in dependency output location
            3. Including and excluding dependencies by scope
            4. Fine-tuning: dependency includes and excludes
            5. Transitive dependencies, project attachments, and project artifacts
            6. Advanced unpacking options
            7. Summarizing dependency sets
          5. moduleSets Sections
            1. Module selection
            2. Sources section
            3. Interpolation of outputDirectoryMapping in moduleSets
            4. Binaries section
            5. moduleSets, parent POMs, and the binaries section
          6. Repositories Section
          7. Managing the Assembly’s Root Directory
          8. componentDescriptors and containerDescriptorHandlers
        6. Best Practices
          1. Standard, Reusable Assembly Descriptors
          2. Distribution (Aggregating) Assemblies
        7. Summary
      6. 13. Properties and Resource Filtering
        1. Introduction
        2. Maven Properties
          1. Maven Project Properties
          2. Maven Settings Properties
          3. Environment Variable Properties
          4. Java System Properties
          5. User-Defined Properties
        3. Resource Filtering
      7. 14. Maven and Eclipse: m2eclipse
        1. Introduction
        2. m2eclipse
        3. Installing the m2eclipse Plugin
          1. Installing Prerequisites
            1. Installing Subclipse
            2. Installing Mylyn
            3. Installing AspectJ Development Tools (AJDT)
            4. Installing the Web Tools Platform (WTP)
          2. Installing m2eclipse
        4. Enabling the Maven Console
        5. Creating a Maven Project
          1. Checking Out a Maven Project from SCM
          2. Creating a Maven Project from a Maven Archetype
          3. Creating a Maven Module
        6. Create a Maven POM File
        7. Importing Maven Projects
          1. Importing a Maven Project
          2. Materializing a Maven Project
        8. Running Maven Builds
        9. Working with Maven Projects
          1. Adding and Updating Dependencies and Plugins
          2. Creating a Maven Module
          3. Downloading Source
          4. Opening Project Pages
          5. Resolving Dependencies
        10. Working with Maven Repositories
          1. Searching For Maven Artifacts and Java classes
          2. Indexing Maven Repositories
        11. Using the Form-Based POM Editor
        12. Analyzing Project Dependencies in m2eclipse
        13. Maven Preferences
        14. Summary
      8. 15. Site Generation
        1. Introduction
        2. Building a Project Site with Maven
        3. Customizing the Site Descriptor
          1. Customizing the Header Graphics
          2. Customizing the Navigation Menu
        4. Site Directory Structure
        5. Writing Project Documentation
          1. APT Example
          2. FML Example
        6. Deploying Your Project Web Site
          1. Configuring Server Authentication
          2. Configuring File and Directory Modes
        7. Customizing Site Appearance
          1. Customizing the Site CSS
          2. Create a Custom Site Template
          3. Reusable Web Site Skins
          4. Creating a Custom Theme CSS
          5. Customizing Site Templates in a Skin
        8. Tips and Tricks
          1. Inject XHTML into HEAD
          2. Add Links Under Your Site Logo
          3. Add Breadcrumbs to Your Site
          4. Add the Project Version
          5. Modify the Publication Date Format and Location
          6. Using Doxia Macros
      9. 16. Repository Manager
        1. Introduction
          1. History of Nexus
        2. Installing Nexus
          1. Downloading Nexus from Sonatype
          2. Installing Nexus
          3. Running Nexus
          4. Post-Install Checklist
          5. Startup Scripts for Linux
            1. Add Nexus as a service on Red Hat, Fedora, and CentOS
            2. Add Nexus as a service on Ubuntu
          6. Running Nexus Behind a Proxy
        3. Using Nexus
          1. Browsing Repositories
          2. Browsing Groups
          3. Searching for Artifacts
          4. Browsing System Feeds
          5. Browsing Log Files and Configuration
          6. Changing Your Password
        4. Configuring Maven to Use Nexus Repositories
          1. Using the Nexus Central Proxy Repository
          2. Using Nexus for Snapshot Repositories
          3. Adding Custom Repositories for Missing Dependencies
          4. Adding a New Repository
          5. Adding a Repository to a Group
        5. Configuring Nexus
          1. Customizing Server Configuration
          2. Managing Repositories
          3. Managing Groups
          4. Managing Routes
          5. Managing Scheduled Services
          6. Managing Security
            1. Managing privileges
            2. Managing repository targets
            3. Managing security roles
            4. Managing users
          7. Network Configuration
        6. Maintaining Repositories
          1. Uploading Artifacts to Hosted Repositories
        7. Deploying Artifacts to Nexus
          1. Configuring Deployment Security
          2. Deploying Releases
          3. Deploying Snapshots
          4. Deploying Third-Party Artifacts
      10. 17. Writing Plugins
        1. Introduction
        2. Programming Maven
          1. What Is Inversion of Control?
          2. Introduction to Plexus
          3. Why Plexus?
          4. What Is a Plugin?
        3. Plugin Descriptor
          1. Top-Level Plugin Descriptor Elements
          2. Mojo Configuration
          3. Plugin Dependencies
        4. Writing a Custom Plugin
          1. Creating a Plugin Project
          2. A Simple Java Mojo
          3. Configuring a Plugin Prefix
          4. Logging from a Plugin
          5. Mojo Class Annotations
          6. When a Mojo Fails
        5. Mojo Parameters
          1. Supplying Values for Mojo Parameters
          2. Multivalued Mojo Parameters
          3. Depending on Plexus Components
          4. Mojo Parameter Annotations
        6. Plugins and the Maven Lifecycle
          1. Executing a Parallel Lifecycle
          2. Creating a Custom Lifecycle
          3. Overriding the Default Lifecycle
      11. 18. Writing Plugins in Alternative Languages
        1. Writing Plugins in Ant
        2. Creating an Ant Plugin
        3. Writing Plugins in JRuby
          1. Creating a JRuby Plugin
          2. Ruby Mojo Implementations
          3. Logging from a Ruby Mojo
          4. Raising a MojoError
          5. Referencing Plexus Components from JRuby
        4. Writing Plugins in Groovy
          1. Creating a Groovy Plugin
    7. IV. Appendixes
      1. A. Settings Details
        1. Quick Overview
        2. Settings Details
          1. Simple Values
          2. Servers
          3. Mirrors
          4. Proxies
          5. Profiles
          6. Activation
          7. Properties
          8. Repositories
          9. Plugin Repositories
          10. Active Profiles
      2. B. Sun Specification Alternatives
    8. Index
    9. About the Author
    10. Colophon
    11. SPECIAL OFFER: Upgrade this ebook with O’Reilly