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/
Ad

More Related Content

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
Mert Çalışkan
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins
 
Apache Maven
Apache MavenApache Maven
Apache Maven
Rahul Tanwani
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
Mika Koivisto
 
Maven ppt
Maven pptMaven ppt
Maven ppt
natashasweety7
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Onkar Deshpande
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad
 
Maven
MavenMaven
Maven
Марія Русин
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
Robert Burrell Donkin
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
David Noble
 
Maven basics
Maven basicsMaven basics
Maven basics
Vijay Krishnan Ramaswamy
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
Return on Intelligence
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
Dragos Balan
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
andyhot
 

Similar to Note - Apache Maven Intro (20)

Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
Shuji Watanabe
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz
 
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
 
Mavenppt
MavenpptMavenppt
Mavenppt
Surekha Achanta
 
Maven
MavenMaven
Maven
Fabio Bonfante
 
Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)
Hussain Mansoor
 
Apache Maven for AT/QC
Apache Maven for AT/QCApache Maven for AT/QC
Apache Maven for AT/QC
Volodymyr Ostapiv
 
Wonderful World of Maven
Wonderful World of MavenWonderful World of Maven
Wonderful World of Maven
Justin J. Moses
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
People Strategists
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
Mithilesh Singh
 
An Introduction to Maven and Flex
An Introduction to Maven and FlexAn Introduction to Maven and Flex
An Introduction to Maven and Flex
Justin J. Moses
 
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
Dmitry Bakaleinik
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
Anand kalla
 
Maven
MavenMaven
Maven
Sandesh Sharma
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
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)
Robert Scholte
 
Maven
MavenMaven
Maven
javeed_mhd
 
Maven
MavenMaven
Maven
AbdulImrankhan7
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
Shuji Watanabe
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz
 
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 basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)
Hussain Mansoor
 
Wonderful World of Maven
Wonderful World of MavenWonderful World of Maven
Wonderful World of Maven
Justin J. Moses
 
An Introduction to Maven and Flex
An Introduction to Maven and FlexAn Introduction to Maven and Flex
An Introduction to Maven and Flex
Justin J. Moses
 
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
Dmitry Bakaleinik
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
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)
Robert Scholte
 
Ad

Recently uploaded (20)

Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Ad

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/