Maven

From HaFrWiki42
Jump to navigation Jump to search

A maven is an expert in a particular field. The word comes from Yiddish. Maven is a through development of Ant [1], but works completely different.
Maven is succeeded by Maven 2 which has a different approach from version 1.


Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

Programming

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

What is it

Maven provides a comprehensive approach to managing software projects. From compilation, to distribution, to documentation, to team collaboration, Maven provides the necessary abstractions that encourage reuse and take much of the work out of project builds.
[Better Builds with Maven, p.22]

Concepts

  • Repositories for Artifacts
  • POM (Project Object Model)
  • Convention over Configuration
  • Reuse of Build Logic

Continuous build

  • Continuum, Apache Project Continuum a continuous integration server for building Java based projects. It supports a wide range of projects.
  • Cruisecontrol, Sourceforge project CruiseControl is a framework for a continuous build process. It includes, but is not limited to, plugins for email notification, Ant, and various source control tools. A web interface is provided to view the details of the current and previous builds.

Install Maven 2

First download Maven from the apache site.

  1. Unpack the archive where you would like to store the binaries, eg:
 tar zxvf maven-2.0.tar.gz

or

 unzip maven-2.0.zip
  1. A directory called "maven-2.0" will be created.
  2. Add the bin directory to your PATH, eg:
   export PATH=/usr/local/maven-2.0/bin:$PATH
 or
   set PATH="c:\program files\maven-2.0\bin";%PATH%
  1. Make sure JAVA_HOME is set to the location of your JDK
  2. Run "mvn --version" to verify that it is correctly installed.

For more information, please see http://maven.apache.org


The default directory of the repository on a WINTEL machine is (the quotes are essential). "%USERPROFILE%\.m2\repository"

Maven User Quick Guide

Backward compatability hwas been the starting point, though there has been changes.

Maven 1.0 Name Maven 2.0 Name
project.xml
project.properties
pom.xml
pom.properties


First Maven Project Creation

Creating your first project! In order to create the simplest of Maven projects, execute the following from the command line:

  mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app

this will create the following pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <reports>
    <report>..</report>
    ...
  </reports>
</project>

Project Object Model (POM)

top The POM is the basic unit of work in Maven containing every important piece of information about your project and is essentially one-stop-shopping for finding anything related to your project.

Name Description
project Top-level element in all Maven pom.xml files.
modelVersion Indicates version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
groupId Indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
artifactId Indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by would have the form <artifactId>-<version>.<extension> (for example, myapp-1.0.jar).
packaging Indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects.
version Indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
name Indicates the display name used for the project. This is often used in Maven's generated documentation.
url Indicates where the project's site can be found. This is often used in Maven's generated documentation.
description Provides a basic description of your project. This is often used in Maven's generated documentation.


Name Example
project <project xmlns="http://maven.apache.org/POM/4.0.0" mlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
modelVersion <modelVersion>4.0.0</modelVersion>
groupId <groupId>com.mycompany.app</groupId>
artifactId <artifactId>my-app</artifactId>
packaging <packaging>jar</packaging>
version <version>1.0-SNAPSHOT</version>
name <name>Maven Quick Start Archetype</name>
url <url>http://maven.apache.org</url>
description <description>Descirption of Maven</description>



Plugins

Maven should download plugins by itself. Unfortunately a redirection is used maven can not handle. To download a new/changed plugin use:

maven plugin:download 
                 -DgroupId=<groupId>
                 -DartifactId=<atifactId>
                 -Dversion=<versionNumber>
                 -Dmaven.repo.remote=http://repo1.maven.org/maven,http://people.apache.org/repo

Example:

maven plugin:download 
                 -DgroupId=maven 
                 -DartifactId=maven-simian-plugin 
                 -Dversion=1.6.1 
                 -Dmaven.repo.remote=http://repo1.maven.org/maven,http://people.apache.org/repo

Don't forget to remove the older version of the plugin from your repository cash. There are 3 plugin directories. Suppose you have entered in the build.properties, located in the USERPROFILE folder, the label value pair:

maven.home.local = C:/TEMP/maven-1.1-beta-2/.maven

then the (relative) path names mean:

Plugin Description
../plugins Source directory
../.maven/cache Unpacked plugin directory (repository cash)
../maven/plugins User plugin directory

See also

top

  • Apache-Maven, The Apache-Maven-Home-Site of all versions.
  • Browse/Search Maven Repositories, Use this site for your searches for repositories and how to use them in Maven.
  • Maven in Wikipedia. A maven (also mavin) is a trusted expert in a particular field, who seeks to pass knowledge on to others.
    The word maven comes from the Hebrew, via Yiddish, and means one who understands, based on an accumulation of knowledge. See Apache Maven forthe Computer Maven version.
  • Maven 2 See also contains more links.

Maven 1

Maven 2

  • Maven 2, Harm's wiki special for Maven 2.
  • Maven 2, Home of the 2nd version of Maven. The latest Maven-version is 3.0.3 (  © 19 May 2011, last modified: GMT: 03:53, 2024 December 12, Maven).
  • Maven 2 Repository, The original Maven 2 repository. Do not browse, use the Search instead.
  • Maven 2 Repository Mirror --can be slow to load, is an alternative for the Maven 2 Maven 2 repository.

Related

  • Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
  • CodeHaus is a collaborative environment for building opensource projects with a strong emphasis on modern languages, focussed on quality components that meet real world needs.
  • Ibiblio Website of Ibiblio, The Public's Library and Digital Archive. A public interface to read public domain books online. And the home-site for maven repository mirrors.


Developers Notebook

To use maven, read the maven Developers Notebook, by Vincent Massol and Timothy O'Brien.

Jars for Maven

Missing jars for maven? Look here:

Plugins for Maven

Many plugins are available. The ones named below have a special page on this site.


How to get Maven

Example Files

See also

  • Maven 2, the successor of Maven version 1 has a different POM and command line name.
  • Coding Standards, Quality control of the programming standards.

If you like Maven you may like Ant too.

Reference

top

  1. Apache home of Maven and Ant