SlideShare a Scribd company logo
Apache Maven (3.0+)
Basic introduction
Dec.22.2013
Boy.Wang
Jar Hell & Plugin Hell
cosmos-saje
cosmos-lib saje
cosmos-core
xerces fscript fractal-adl dream-annot dream-core
antlr fractal-util julia-mixins perseus-cache
task-deployment julia-asm aval
fractal-rmi
easymock
developing project
intermediate depex
final depex
Main Purpose
1. Single project producing a single type.
2. Standard life-cycles and naming conventions.
3. Version and dependency management.
4. Repositories: several remote and one local, it means no
more externals or lib and no more jars in developer's
directories.
groupId artifactId version
Maven Working Flow
Maven
(core)
~/.m2/
repository
pom.xml
download
parse connect
plugins
libs artifacts
artifacts
use
The core of Maven consists of a very basic shell that knows only how to parse the command line, manage a
classpath, parse a POM file and download Maven plugins as needed.
Core Concepts
1. What is pom.xml?
2. What is Maven plugin and goal?
e.g. mvn archetype:generate -DgroupId=org.simple -DartifactId=simple
3. What is Maven lifecycle and phase?
e.g. mvn install
4. What is Maven coordinate?
5. What is Maven repositories and dependency?
6. What is Maven artifact?
mvn [options] [goal(s)] [phase(s)]
1. A Maven project is simply a folder that contains a pom.xml.
2. Every pom.xml implicitly inherits from Super POM.
http://maven.apache.org/ref/3.0.5/maven-model-builder/super-pom.html
pom.xml (Project Object Model)
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.demo</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myapp</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>
</project>
SAMPLE
Maven Plugin and Goal
1. A plugin is a collection of one or more goals.
a. Plugin can be written in Java, Ant or Ruby.
b. e.g. Jar plugin contains goals for creating JAR files.
c. e.g. Compiler plugin contains goals for compiling
source code and unit test.
2. A goal is a specific task that can be executed.
% mvn archetype:generate -DgroupId=xxx.yyy -DartifactId=simple
plugin's identifier goal's parameters
goal's identifier
Maven Lifecycle and Phase
1. Phase may have zero or more goals bound to it.
2. Lifecycle is the definition of an ordered list of phases which is
executed sequentially.
% mvn resources:resources 
compiler:compile 
resources:testResources 
compiler:testCompile 
surefire:test 
jar:jar 
install:install 
% mvn install
phase's identifier Is the same with...
Lifecycle is just like a lazy package that is made of Phases. It helps you to execute multiple Goals sequentially.
% mvn compile
generate-sources
compile
test-compile
test
package
install
deploy
Phase Plugin:Goal
ear:generate...
compiler:compile
compiler:testCompile
surefire:test
jar:jar
install:install
deploy:deploy
lifecycle:
generate-source -> compile
lifecycle:
generate-source -> compile -> ... -> deploy
% mvn deploy
Maven Coordinate
Maven coordinates define a set of identifiers which can be
used to uniquely identify a project.
<project ...>
...
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<packaging>jar</packaging>
<version>8.3.0-SNAPSHOT</version>
This packaging element affects the goals required by phases.
Maven Repositories and Depex
1. When you run Maven for the first time, you will notice that Maven
downloads a number of files from a remote Maven repository. In
Maven, artifacts and plugins are retrieved from a remote
repository when they are needed.
2. Maven uses the local repository to share dependencies across
local projects.
Maven publishes a JAR file and a slightly modified version of the project’s
pom.xml file in the local repository. Storing a POM file in the repository gives
other projects information about this project, most importantly what
dependencies it has.
% mvn install
Maven Artifact
An Maven artifact is a file that is produced by a build
execution and represents an application binary. e.g.
1. A project's library: JAR, WAR, EAR, ZIP, ....
2. Maven plugin: A JAR application to execute build
executions.
3. Maven archetype: A JAR application to create a Maven
project template.
4. Project metafile: pom.xml.
Summary
1. A goal is a "unit of work". It is a basic execution unit and
its behavior can be configured.
2. A phase is made up of goals and a lifecycle is made up of
phases.
3. Higher level of reusability between builds.
4. Maven is a build system not just a build tool.
Appendix
Reference
1. Free Books
a. http://www.sonatype.com/resources/books/maven-by-example
b. http://www.sonatype.com/resources/books/maven-the-complete-reference
2. Maven Lifecycle Reference
a. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
b. http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html
3. Maven C/C++ Plugin
a. http://duns.github.io/maven-nar-plugin/

More Related Content

What's hot

Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 

What's hot (20)

Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven
MavenMaven
Maven
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 

Similar to Note - Apache Maven Intro

Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 

Similar to Note - Apache Maven Intro (20)

Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Maven
MavenMaven
Maven
 
Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)
 
Apache Maven for AT/QC
Apache Maven for AT/QCApache Maven for AT/QC
Apache Maven for AT/QC
 
Wonderful World of Maven
Wonderful World of MavenWonderful World of Maven
Wonderful World of Maven
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
An Introduction to Maven and Flex
An Introduction to Maven and FlexAn Introduction to Maven and Flex
An Introduction to Maven and Flex
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Maven
MavenMaven
Maven
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 

Recently uploaded (20)

GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 

Note - Apache Maven Intro

  • 1. Apache Maven (3.0+) Basic introduction Dec.22.2013 Boy.Wang
  • 2. Jar Hell & Plugin Hell cosmos-saje cosmos-lib saje cosmos-core xerces fscript fractal-adl dream-annot dream-core antlr fractal-util julia-mixins perseus-cache task-deployment julia-asm aval fractal-rmi easymock developing project intermediate depex final depex
  • 3. Main Purpose 1. Single project producing a single type. 2. Standard life-cycles and naming conventions. 3. Version and dependency management. 4. Repositories: several remote and one local, it means no more externals or lib and no more jars in developer's directories. groupId artifactId version
  • 4. Maven Working Flow Maven (core) ~/.m2/ repository pom.xml download parse connect plugins libs artifacts artifacts use The core of Maven consists of a very basic shell that knows only how to parse the command line, manage a classpath, parse a POM file and download Maven plugins as needed.
  • 5. Core Concepts 1. What is pom.xml? 2. What is Maven plugin and goal? e.g. mvn archetype:generate -DgroupId=org.simple -DartifactId=simple 3. What is Maven lifecycle and phase? e.g. mvn install 4. What is Maven coordinate? 5. What is Maven repositories and dependency? 6. What is Maven artifact? mvn [options] [goal(s)] [phase(s)]
  • 6. 1. A Maven project is simply a folder that contains a pom.xml. 2. Every pom.xml implicitly inherits from Super POM. http://maven.apache.org/ref/3.0.5/maven-model-builder/super-pom.html pom.xml (Project Object Model) <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.demo</groupId> <artifactId>myapp</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>myapp</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> </project> SAMPLE
  • 7. Maven Plugin and Goal 1. A plugin is a collection of one or more goals. a. Plugin can be written in Java, Ant or Ruby. b. e.g. Jar plugin contains goals for creating JAR files. c. e.g. Compiler plugin contains goals for compiling source code and unit test. 2. A goal is a specific task that can be executed. % mvn archetype:generate -DgroupId=xxx.yyy -DartifactId=simple plugin's identifier goal's parameters goal's identifier
  • 8. Maven Lifecycle and Phase 1. Phase may have zero or more goals bound to it. 2. Lifecycle is the definition of an ordered list of phases which is executed sequentially. % mvn resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test jar:jar install:install % mvn install phase's identifier Is the same with...
  • 9. Lifecycle is just like a lazy package that is made of Phases. It helps you to execute multiple Goals sequentially. % mvn compile generate-sources compile test-compile test package install deploy Phase Plugin:Goal ear:generate... compiler:compile compiler:testCompile surefire:test jar:jar install:install deploy:deploy lifecycle: generate-source -> compile lifecycle: generate-source -> compile -> ... -> deploy % mvn deploy
  • 10. Maven Coordinate Maven coordinates define a set of identifiers which can be used to uniquely identify a project. <project ...> ... ... <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> <groupId>org.eclipse.cdt</groupId> <artifactId>cdt-parent</artifactId> <packaging>jar</packaging> <version>8.3.0-SNAPSHOT</version> This packaging element affects the goals required by phases.
  • 11. Maven Repositories and Depex 1. When you run Maven for the first time, you will notice that Maven downloads a number of files from a remote Maven repository. In Maven, artifacts and plugins are retrieved from a remote repository when they are needed. 2. Maven uses the local repository to share dependencies across local projects. Maven publishes a JAR file and a slightly modified version of the project’s pom.xml file in the local repository. Storing a POM file in the repository gives other projects information about this project, most importantly what dependencies it has. % mvn install
  • 12. Maven Artifact An Maven artifact is a file that is produced by a build execution and represents an application binary. e.g. 1. A project's library: JAR, WAR, EAR, ZIP, .... 2. Maven plugin: A JAR application to execute build executions. 3. Maven archetype: A JAR application to create a Maven project template. 4. Project metafile: pom.xml.
  • 13. Summary 1. A goal is a "unit of work". It is a basic execution unit and its behavior can be configured. 2. A phase is made up of goals and a lifecycle is made up of phases. 3. Higher level of reusability between builds. 4. Maven is a build system not just a build tool.
  • 15. Reference 1. Free Books a. http://www.sonatype.com/resources/books/maven-by-example b. http://www.sonatype.com/resources/books/maven-the-complete-reference 2. Maven Lifecycle Reference a. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference b. http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html 3. Maven C/C++ Plugin a. http://duns.github.io/maven-nar-plugin/