SlideShare a Scribd company logo
Maven
Sandesh Sharma
MAVEN
• What is MAVEN
• Installation
• Components
• Configurations
• Errors and Solutions
• Queries
Maven
“a project management tool”

Reports
Generate a web site
Facilitate communication
Installation
• Step 1. Download Apache Maven
–wget
http://www.apache.org/dist//maven/binaries
/apache-maven-3.0.3-bin.tar.gz
• Step 2. Extract archive
–tar -zxvf apache-maven-3.0.3-bin.tar.gz
• Step 3. Add the M2_HOME environment
variable
–nano .bashrc
–export M2_HOME=/opt/apache-maven-3.0.3
–export PATH=${M2_HOME}/bin:${PATH}
• Step 4. Verify installation of Apache Maven
User-specific Configuration and
Repository
• ~/.m2/settings.xml
• ~/.m2/repository/
Components
Creating A Simple Project
What’s In That
Building A simple Project
Go to directory which contains pom.xml
Maven POM
• Stands for Project Object Model
• Describes a project
– Name and Version
– Artifact Type
– Source Code Locations
– Dependencies
– Plugins
– Profiles (Alternate build configurations)
• Uses XML by Default
– Not the way Ant uses XML
Packaging
• Build type identified using the “packaging”
element
• Tells Maven how to build the project
• Example packaging types:
– pom, jar, war, ear, custom
– Default is jar

<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-training</artifactId>
<groupId>org.lds.training</groupId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
Maven Build Lifecycle
• A Maven build follow a lifecycle
• Default lifecycle

– generate-sources/generate-resources
– compile
– test
– package
– integration-test (pre and post)
– Install
– deploy

• There is also a Clean lifecycle
• Dependencies consist of:

– GAV
– Scope: compile, test, provided (default=compile)
– Type: jar, pom, war, ear, zip (default=jar)

<project>
...
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Maven Repositories
• Dependencies are downloaded from repositories
– Via http

• Downloaded dependencies are cached in a local
repository
– Usually found in ${user.home}/.m2/repository

• Repository follows a simple directory structure

– {groupId}/{artifactId}/{version}/{artifactId}-{version}.jar
– groupId ‘.’ is replaced with ‘/’

• Maven Central is primary community repo
– http://repo1.maven.org/maven2
Defining a repository
• Repositories are defined in the pom
• Repositories can be inherited from parent
• Repositories are keyed by id
• Downloading snapshots can be controlled

<project>
...
<repositories>
<repository>
<id>lds-main</id>
<name>LDS Main Repo</name>
<url>http://code.lds.org/nexus/content/groups/main-repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
Dependency Exclusions
• Exclusions exclude transitive dependencies
• Dependency consumer solution
<project>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Optional Dependencies
• Don’t propagate dependency transitively
• Dependency producer solution
• Optional is under used
<project>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Dependency Management
• What do you do when versions collide?
– Allow Maven to manage it?
– Complex and less predictable

– Take control yourself

– Manage the version manually

<project>
• In Java you cannot use both versions
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Using Dependency
Management

<project>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency> <!-- Look ma, no version! -->
</dependencies>
</project>

• Other uses for Dependency Management
– Allowing parent pom to manage versions
– Unify exclusions
Maven

More Related Content

PPT
Maven Introduction
PPTX
Maven tutorial
PPTX
Learning Maven by Example
PDF
Liferay maven sdk
PDF
Maven 3 Overview
PDF
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
KEY
Play Support in Cloud Foundry
PPTX
Maven Basics - Explained
Maven Introduction
Maven tutorial
Learning Maven by Example
Liferay maven sdk
Maven 3 Overview
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
Play Support in Cloud Foundry
Maven Basics - Explained

What's hot (20)

PPTX
Development Tools - Maven
PPTX
Apache maven 2 overview
PPTX
Introduction to Maven
PPTX
Introduction to maven
PDF
Note - Apache Maven Intro
PPTX
SBT by Aform Research, Saulius Valatka
PDF
Hands On with Maven
PDF
Apache Jackrabbit Oak on MongoDB
PDF
AWS ElasticBeanstalk Advanced configuration
PPTX
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
PPTX
Maven for Dummies
PDF
Extending Build to the Client: A Maven User's Guide to Grunt.js
PDF
Java Builds with Maven and Ant
PDF
Cloud Foundry Open Tour India 2012 , Keynote
KEY
Selenium Grid
PPTX
Go Faster with Ansible (PHP meetup)
ODP
The secret life of a dispatcher (Adobe CQ AEM)
PDF
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
PDF
Ansible
PDF
maven
Development Tools - Maven
Apache maven 2 overview
Introduction to Maven
Introduction to maven
Note - Apache Maven Intro
SBT by Aform Research, Saulius Valatka
Hands On with Maven
Apache Jackrabbit Oak on MongoDB
AWS ElasticBeanstalk Advanced configuration
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
Maven for Dummies
Extending Build to the Client: A Maven User's Guide to Grunt.js
Java Builds with Maven and Ant
Cloud Foundry Open Tour India 2012 , Keynote
Selenium Grid
Go Faster with Ansible (PHP meetup)
The secret life of a dispatcher (Adobe CQ AEM)
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Ansible
maven
Ad

Viewers also liked (12)

PDF
Morte de chávez e a volta da autonomia petrolífera dos eua
PPT
Ford bpn show 10-12
PPT
Spring, web service, web server, eclipse by a introduction sandesh sharma
PDF
Censimento funghi ospedale Sacile 2013
PDF
14250 ch2
PDF
PPT
Automated code review process
PPT
OOP and java by a introduction sandesh sharma
PPT
Service oriented architecture
PPTX
Levis final
PPT
Core java by a introduction sandesh sharma
PPT
Stitch, seam ppt
Morte de chávez e a volta da autonomia petrolífera dos eua
Ford bpn show 10-12
Spring, web service, web server, eclipse by a introduction sandesh sharma
Censimento funghi ospedale Sacile 2013
14250 ch2
Automated code review process
OOP and java by a introduction sandesh sharma
Service oriented architecture
Levis final
Core java by a introduction sandesh sharma
Stitch, seam ppt
Ad

Similar to Maven (20)

PPT
Introduction tomaven
PPTX
PDF
Apache maven, a software project management tool
PDF
Build Automation using Maven
PDF
Apache maven
PDF
Fundamental of apache maven
PPSX
Maven Presentation - SureFire vs FailSafe
PDF
Mavennotes.pdf
PPT
MAVEN
PDF
A-Z_Maven.pdf
PPTX
Maven
PPTX
Apache Maven basics
PPTX
An Introduction to Maven
PPTX
Apache Maven for AT/QC
PDF
PDF
PPTX
Maven and versioning
PPTX
Introduction to Maven for beginners and DevOps
Introduction tomaven
Apache maven, a software project management tool
Build Automation using Maven
Apache maven
Fundamental of apache maven
Maven Presentation - SureFire vs FailSafe
Mavennotes.pdf
MAVEN
A-Z_Maven.pdf
Maven
Apache Maven basics
An Introduction to Maven
Apache Maven for AT/QC
Maven and versioning
Introduction to Maven for beginners and DevOps

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf

Maven

  • 2. MAVEN • What is MAVEN • Installation • Components • Configurations • Errors and Solutions • Queries
  • 3. Maven “a project management tool” Reports Generate a web site Facilitate communication
  • 4. Installation • Step 1. Download Apache Maven –wget http://www.apache.org/dist//maven/binaries /apache-maven-3.0.3-bin.tar.gz • Step 2. Extract archive –tar -zxvf apache-maven-3.0.3-bin.tar.gz • Step 3. Add the M2_HOME environment variable –nano .bashrc –export M2_HOME=/opt/apache-maven-3.0.3 –export PATH=${M2_HOME}/bin:${PATH} • Step 4. Verify installation of Apache Maven
  • 5. User-specific Configuration and Repository • ~/.m2/settings.xml • ~/.m2/repository/
  • 9. Building A simple Project Go to directory which contains pom.xml
  • 10. Maven POM • Stands for Project Object Model • Describes a project – Name and Version – Artifact Type – Source Code Locations – Dependencies – Plugins – Profiles (Alternate build configurations) • Uses XML by Default – Not the way Ant uses XML
  • 11. Packaging • Build type identified using the “packaging” element • Tells Maven how to build the project • Example packaging types: – pom, jar, war, ear, custom – Default is jar <?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <artifactId>maven-training</artifactId> <groupId>org.lds.training</groupId> <version>1.0</version> <packaging>jar</packaging> </project>
  • 12. Maven Build Lifecycle • A Maven build follow a lifecycle • Default lifecycle – generate-sources/generate-resources – compile – test – package – integration-test (pre and post) – Install – deploy • There is also a Clean lifecycle
  • 13. • Dependencies consist of: – GAV – Scope: compile, test, provided (default=compile) – Type: jar, pom, war, ear, zip (default=jar) <project> ... <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> </dependencies> </project>
  • 14. Maven Repositories • Dependencies are downloaded from repositories – Via http • Downloaded dependencies are cached in a local repository – Usually found in ${user.home}/.m2/repository • Repository follows a simple directory structure – {groupId}/{artifactId}/{version}/{artifactId}-{version}.jar – groupId ‘.’ is replaced with ‘/’ • Maven Central is primary community repo – http://repo1.maven.org/maven2
  • 15. Defining a repository • Repositories are defined in the pom • Repositories can be inherited from parent • Repositories are keyed by id • Downloading snapshots can be controlled <project> ... <repositories> <repository> <id>lds-main</id> <name>LDS Main Repo</name> <url>http://code.lds.org/nexus/content/groups/main-repo</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
  • 16. Dependency Exclusions • Exclusions exclude transitive dependencies • Dependency consumer solution <project> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>
  • 17. Optional Dependencies • Don’t propagate dependency transitively • Dependency producer solution • Optional is under used <project> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> <optional>true</optional> </dependency> </dependencies> </project>
  • 18. Dependency Management • What do you do when versions collide? – Allow Maven to manage it? – Complex and less predictable – Take control yourself – Manage the version manually <project> • In Java you cannot use both versions ... <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> </dependency> </dependencies> </dependencyManagement> </project>