Anda di halaman 1dari 19

Maven

Manpreet Singh Randhawa

Agenda

Introduction Need Features Overview Demo Resources

Introduction
Maven

Maven
A Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project.

Several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS.

Required a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information and a way to share JARs across several projects.

Need
Maven

Dependency Management of being a Dependency management has a long tradition

complicated mess for anything but the most trivial of projects. Jarmageddon quickly ensues as the dependency tree becomes large and complicated. "Jar Hell" follows, where versions of dependencies on one system are not equivalent to versions as those developed with, either by the wrong version given, or conflicting versions between similarly named jars.

Maven solves both problems through a common local repository from which to link projects correctly, versions and all.

Objectives

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.

Ant vs Maven
Apache Ant:
Ant doesnt have formal conventions like a common project directory structure or default behavior. You have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they havent been codified into the product.

Ant is procedural. You have to tell Ant exactly what to do and when to do it. You have to tell it to compile, then copy, then compress.

Ant doesnt have a lifecycle. You have to define goals and goal dependencies. You have to attach a sequence of tasks to each goal manually.

Ant vs Maven
Apache Maven:
Maven has conventions. It knows where your source code is because you followed the convention. Mavens Compiler plugin put the bytecode in target/classes, and it produces a JAR file in target.

Maven is declarative. All you had to do was create a pom.xml file and put your source in the default directory. Maven took care of the rest.

Maven has a lifecycle which was invoked when you executed mvn install. This command told Maven to execute a series of sequential lifecycle phases until it reached the install lifecycle phase. As a side-effect of this journey through the lifecycle, Maven executed a number of default plugin goals which did things like compile and

Features
Maven

Features

Simple project setup that follows best practices. Consistent usage across all projects.

Superior dependency management: Maven encourages the use of a central repository of JARs and other dependencies..

Easily work with multiple projects at the same time.

A large and growing repository of libraries and metadata to use out of the box.

Extensible, with the ability to easily write plugins in Java or scripting languages.

Model based builds into predefined output types such as a JAR, WAR, or distribution based on metadata about the

Features
Release management and distribution publication: Without much additional configuration, Maven will integrate with your source control system such as CVS and manage the release of a project based on a certain tag. It can also publish this to a distribution location for use by other projects.

Overview
Maven

Installation
Maven is a Java tool, so you must have Java installed in order to proceed. First, download Maven and follow installation instructions. After that, type the following in a terminal or in a command prompt:

mvn --version

It should print out your installed version of Maven.

Creating a Project
On your command line, execute the following Maven goal: mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=myapp

You will notice that the create goal created a directory with the same name given as the artifactId. Change into that directory. cd my-app

Under this directory you will notice the standard project

Running Maven Tools


validate: validate the project is correct and all necessary information is available.

compile: compile the source code of the project.

test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.

package: take the compiled code and package it in its distributable format, such as a JAR.

integration-test: process and deploy the package if necessary into an environment where integration tests can be run.

verify: run any checks to verify the package is valid and

Running Maven Tools


install: install the package into the local repository, for use as a dependency in other projects locally.

deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

clean: cleans up artifacts created by prior builds. site: generates site documentation for this project

mvn site

DEMO
Maven

Resources

Apache Maven: Maven: The Definitive Guide: Better Builds with Maven:

http://maven.apache.org/

http://www.sonatype.com/books/maven-book/

http://www.maestrodev.com/better-build-maven

Anda mungkin juga menyukai