SlideShare a Scribd company logo
Maven
Prepared By : Smita Prasad
Topics to be covered
• What is Maven and its setup
• POM
• Relationships
• Creating a project
• Execution Groups
• Mvn command
• Built-in Lifecycles
• Build Settings
• Dependency Management
Common Problems and Activities
• Multiple Jars
• Jar have Dependencies and versions
• Project Structure
• Building , Publishing and Deploying
What is Maven?
• Maven, is a Yiddish word meaning
“Accumulator Of Knowledge”
• It is a Plugin Execution Framework
• Used for software lifecycle management
• Provides a cohesive suite of plugins for
• verification,
• compilation,
• testing,
• packaging,
• reporting,
• and deployment.
Interoperability and Extensibility
• It offers easy-to-write custom build-
supplementing plugins
• Reuses any desired aspect of Ant
• Can compile native C, C++, and .NET code
• Strong support for Java and JVM languages
and platforms, such as Scala, JRuby, Groovy
and Grails.
• For PHP users there is a separate project by
Apache called PHP-Maven.
History
Maven began its life in the Jakarta Alexandria project.
The Alexandria project is now defunct.
It was only part of this for 5 months.
Ant v/s Maven
Installing Apache Maven
• Extract the archive and adding the bin folder with the mvn command to the PATH.
• Detailed steps are:
– Ensure JAVA_HOME environment variable is set and points to your JDK
installation
– Setup M2_HOME to a directory under the windows user directory with a folder
called .m2
– Extract distribution archive in any directory
– unzip apache-maven-3.3.3-bin.zip
– Add the bin directory of the created directory apache-maven-3.3.3 to
the PATH environment variable
– Confirm with mvn -v in a new shell. The result should look similar to
set M2_HOME=c:maven-3.2.x-SNAPSHOT
set PATH=%M2_HOME%bin;%PATH%
POM
• POM stands for
"Project Object
Model“
• XML
representation
of a Maven
project held in a
file
named pom.xml
Artifact Vector
• Each Maven project produces an element, such as a
JAR, WAR or EAR, uniquely identified by a composite of
fields known as groupId, artifactId, packaging, version
and scope.
• This vector of fields uniquely distinguishes a Maven
artifact from all others.
• Many Maven reports and plugins print the details of a
specific artifact in this colon separated fashion:
groupid:artifactid:packaging:version:scope
• An example of this output for the core Spring JAR
would be:
org.springframework:spring:jar:2.5.6:compile
Maven Coordinates
• groupId: This is generally unique amongst an organization or a project. When stored within a
repository, the group acts much like the Java packaging structure does in an operating
system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which
becomes a relative directory structure from the base repository.
– Example: The org.codehaus.mojo group lives within the
directory $M2_REPO/org/codehaus/mojo.
• artifactId: Name that the project is known by.
– Example: my-project lives in $M2_REPO/org/codehaus/mojo/my-project.
• packaging: Project’s artifact type. Default value is jar. The current core packaging values
are: pom, jar, maven-plugin, ejb, war, ear, rar, par. These define the default list of goals which
execute to each corresponding build lifecycle stage for a particular package structure.
• version: Code changes, those changes should be versioned, and this element keeps those
versions in line. It is also used within an artifact's repository to separate versions from each
other.
– Example: my-project version 1.0 files live in the directory
structure $M2_REPO/org/codehaus/mojo/my-project/1.0.
POM Relationships
• Super POM
• Inheritance
• Aggregation
• Properties
• Dependencies
Super POM
Super
POM
POM1 POM2 POM3
• The Super POM is Maven's default POM.
• It is Pseudo-invisible.
• All projects inherit it.
• Specifies file location defaults.
• Locks version of common plugins.
Maven Basics - Explained
Project Inheritance
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
</project>
Parent tags in the module pom
Providing a uniform build system
Project 1
Project 5
Project 2
Project 3
Project 4
POM & Plugins
MAVEN
Project Aggregation
• Instead of specifying the parent POM from the module, it specifies the
modules from the parent POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>my-module</module>
</modules>
</project>
Inheritance Aggregation
When several Maven projects have similar
configurations -- refactor your projects by
pulling out those similar configurations
and making a parent project.
When a group of projects that are built or
processed together -- Create a parent
project and have that parent project
declare those projects as its modules.
Let your Maven projects inherit that
parent project, and those configurations
would then be applied to all of them.
Just build the parent and the rest will
follow.
You can have both Project Inheritance and Project Aggregation at the same time.
You'd just have to apply all three rules:
• Specify in every child POM who their parent POM is.
• Change the parent POMs packaging to the value "pom" .
• Specify in the parent POM the directories of its modules (children POMs)
Properties
• One of the practices that Maven encourages is don't repeat
yourself.
• Maven allows you to use both your own and pre-defined variables
in the POM.
They come in 5 different styles—
1) ${ env.X}  ${ env.PATH}
2) ${ java.X}  ${ java.HOME}
3) ${ project.X}  ${ project.version}
4) ${ system.X}  ${ system.offline}
5) ${X}  ${ someVar}
Creating a Project via Archetype
• $ mvn archetype:generate
• Archetype is a Maven project templating toolkit.
• An archetype is defined as
– an original pattern or model from which all other things of the same kind are
made.
• You can choose from various templates available.
• You can also create your own archetype template.
Maven Basics - Explained
Command to execute--
Directory Structure Created for the project my-app
Pom file generated via archetype
EXECUTION GROUPS
• Maven divides execution into four
nested hierarchies.
• From most-encompassing to most-
specific,
• They are:
Lifecycles, Phases, Plugins and Goals
• Lifecycle - Flow of steps
• Phase - A step in a lifecycle
• Plugin – Logical grouping and
distribution of related goals
• Goal - Single executable task
THE MVN COMMAND
• Maven supplies a Unix shell script and MSDOS
batch file named mvn and mvn.bat
respectively.
• This command is used to start all Maven
builds.
• Optional parameters are supplied in a space-
delimited fashion.
mvn clean package jetty:run –Dmaven.test.skip
Executing a Phase or Goal
• At the command prompt, either a phase or a plugin
goal can be requested.
• Multiple phases or goals can be specified and are
separated by spaces.
• Example -
mvn compile:compile jar:jar
• If you execute a phase, all phases and bound plugin
goals up to that point in the lifecycle are also executed.
• Example -
mvn deploy
This example requests the deploy
lifecycle phase, which will also execute
the verification, compilation, testing
and packaging phases.
Built-in Maven Lifecycles
• Maven ships with three lifecycles; clean,
default, and site.
• The clean lifecycle is simplistic in nature. It
deletes all generated and compiled artifacts in
the output directory.
• The default lifecycle defines the most commonly used phases
for building an application, ranging from compilation of the
code to installation of the completed artifacts, such as a JAR,
into a remote Maven repository.
Maven Basics - Explained
• The site lifecycle generates a project information
web site, and can deploy the artifacts to a specified
web server or local path.
Build Settings
• defaultGoal: the default goal or phase to execute if none is
given.
• directory: This is the directory where the build will dump its
files.
• finalName: This is the name of the bundled project when it is
finally built.It defaults to ${artifactId}-${version}.
• filter: Defines *.properties files that contain a list of
properties that apply to resources on build.
Resources
• Specify where the resource files will be placed in the artifact.
Add Resources to JAR
Just place the files in the “resources
” folder
It is added in JAR under META-INF
folder
Filter Resources
• A resource file may need to contain a value that
can only be supplied at build time.
• To accomplish this in Maven, put a reference to
the property that will contain the value into your
resource file using the syntax
– ${<property name>}
• The property can be one of the values defined in
– your pom.xml,
– a value defined in the user's settings.xml,
– a property defined in an external properties file,
– or a system property.
Enable Filtering
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Filtering Examples
Using External Properties File
application.name=${pom.name}
application.version=${pom.version}
message=${my.filter.value}
In application.properties
my.filter.value=hello!
In filter.properties
In pom.xml
DEPENDENCIES
• To express your project’s reliance on a particular artifact,
you declare a dependency in the project’s pom.xml.
Transitive Dependency
Transitive Dependencies Discovery
Feature Description
Dependency mediation Determines what version of a dependency is to be used when
multiple versions of an artifact are encountered. If two
dependency versions are at the same depth in the dependency
tree, the first declared dependency will be used.
Dependency management Directly specify the versions of artifacts to be used when they are
encountered in transitive dependencies. For an example project C
can include B as a dependency in its dependencyManagement
section and directly control which version of B is to be used when
it is ever referenced.
Dependency scope Includes dependencies as per the current stage of the build
Excluded dependencies Any transitive dependency can be excluede using "exclusion"
element. As example, A depends upon B and B depends upon C
then A can mark C as excluded.
Optional dependencies Any transitive dependency can be marked as optional using
"optional" element. As example, A depends upon B and B
depends upon C. Now B marked C as optional. Then A will not use
C.
DependencyManagement
• Used to pull all the dependency information
into a common POM file, simplifying the
references in the child POM file.
• Used when you have multiple attributes that
you don’t want to retype in under multiple
children projects.
• Used to define a standard version of an
artifact to use across multiple projects.
VISUALIZE Dependencies
• List view
‣ mvn dependency:resolve
• Tree view
‣ mvn dependency:tree
• Plugin list view
‣ mvn dependency:resolve-plugins
Standard Scopes
• Each dependency can specify a scope, which controls its visibility
and inclusion in the final packaged artifact, such as a WAR or EAR.
• Scoping enables you to minimize the JARs that ship with your
product.
Exclusion
Thanks

More Related Content

What's hot (20)

PDF
Maven 3 Overview
Mike Ensor
 
PPTX
Apache tomcat
Shashwat Shriparv
 
PPTX
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
PDF
Spring Boot
Jaran Flaath
 
PPTX
Jenkins tutorial
Mamun Rashid, CCDH
 
PDF
Spring Boot
HongSeong Jeon
 
PPTX
Docker: From Zero to Hero
fazalraja
 
PPTX
Spring boot
Gyanendra Yadav
 
PPTX
Introduction to Maven
Onkar Deshpande
 
PPTX
Docker Basics
DuckDuckGo
 
PPTX
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
PPTX
Containerization and Docker
Megha Bansal
 
PDF
Spring Boot Actuator
Rowell Belen
 
PDF
Introduction to Docker Compose
Ajeet Singh Raina
 
PDF
Spring boot introduction
Rasheed Waraich
 
PDF
Introduction to docker
Instruqt
 
PDF
Docker Introduction
Peng Xiao
 
PDF
Introduction to docker
John Willis
 
PPTX
Introducing Swagger
Tony Tam
 
Maven 3 Overview
Mike Ensor
 
Apache tomcat
Shashwat Shriparv
 
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
Spring Boot
Jaran Flaath
 
Jenkins tutorial
Mamun Rashid, CCDH
 
Spring Boot
HongSeong Jeon
 
Docker: From Zero to Hero
fazalraja
 
Spring boot
Gyanendra Yadav
 
Introduction to Maven
Onkar Deshpande
 
Docker Basics
DuckDuckGo
 
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
Containerization and Docker
Megha Bansal
 
Spring Boot Actuator
Rowell Belen
 
Introduction to Docker Compose
Ajeet Singh Raina
 
Spring boot introduction
Rasheed Waraich
 
Introduction to docker
Instruqt
 
Docker Introduction
Peng Xiao
 
Introduction to docker
John Willis
 
Introducing Swagger
Tony Tam
 

Similar to Maven Basics - Explained (20)

PPTX
Introduction to Maven for beginners and DevOps
SISTechnologies
 
PDF
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik
 
PDF
Apache maven, a software project management tool
Renato Primavera
 
PPSX
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
PPTX
Introduction to maven
Manos Georgopoulos
 
PPTX
Maven
Nishant Arora
 
PDF
Mavennotes.pdf
AnkurSingh656748
 
PDF
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
PDF
Maven
Jyothi Malapati
 
PDF
Maven
Jyothi Malapati
 
PDF
Build Automation using Maven
Ankit Gubrani
 
ODP
Maven in Java EE project
Ondrej Mihályi
 
PPTX
Apache Maven basics
Volodymyr Ostapiv
 
PPT
Mavenppt
Surekha Achanta
 
PPT
Introduction tomaven
Manav Prasad
 
PDF
Java Builds with Maven and Ant
David Noble
 
PDF
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
PDF
A-Z_Maven.pdf
Mithilesh Singh
 
Introduction to Maven for beginners and DevOps
SISTechnologies
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik
 
Apache maven, a software project management tool
Renato Primavera
 
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Introduction to maven
Manos Georgopoulos
 
Mavennotes.pdf
AnkurSingh656748
 
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
Build Automation using Maven
Ankit Gubrani
 
Maven in Java EE project
Ondrej Mihályi
 
Apache Maven basics
Volodymyr Ostapiv
 
Mavenppt
Surekha Achanta
 
Introduction tomaven
Manav Prasad
 
Java Builds with Maven and Ant
David Noble
 
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
A-Z_Maven.pdf
Mithilesh Singh
 
Ad

More from Smita Prasad (6)

PPTX
Intro to React.js
Smita Prasad
 
PPTX
Maven advanced
Smita Prasad
 
PPTX
Spring @Transactional Explained
Smita Prasad
 
PPTX
Learn Apache Shiro
Smita Prasad
 
PPTX
Clean code
Smita Prasad
 
PPTX
PostgreSQL- An Introduction
Smita Prasad
 
Intro to React.js
Smita Prasad
 
Maven advanced
Smita Prasad
 
Spring @Transactional Explained
Smita Prasad
 
Learn Apache Shiro
Smita Prasad
 
Clean code
Smita Prasad
 
PostgreSQL- An Introduction
Smita Prasad
 
Ad

Recently uploaded (20)

PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 

Maven Basics - Explained

  • 1. Maven Prepared By : Smita Prasad
  • 2. Topics to be covered • What is Maven and its setup • POM • Relationships • Creating a project • Execution Groups • Mvn command • Built-in Lifecycles • Build Settings • Dependency Management
  • 3. Common Problems and Activities • Multiple Jars • Jar have Dependencies and versions • Project Structure • Building , Publishing and Deploying
  • 4. What is Maven? • Maven, is a Yiddish word meaning “Accumulator Of Knowledge” • It is a Plugin Execution Framework • Used for software lifecycle management • Provides a cohesive suite of plugins for • verification, • compilation, • testing, • packaging, • reporting, • and deployment.
  • 5. Interoperability and Extensibility • It offers easy-to-write custom build- supplementing plugins • Reuses any desired aspect of Ant • Can compile native C, C++, and .NET code • Strong support for Java and JVM languages and platforms, such as Scala, JRuby, Groovy and Grails. • For PHP users there is a separate project by Apache called PHP-Maven.
  • 6. History Maven began its life in the Jakarta Alexandria project. The Alexandria project is now defunct. It was only part of this for 5 months.
  • 8. Installing Apache Maven • Extract the archive and adding the bin folder with the mvn command to the PATH. • Detailed steps are: – Ensure JAVA_HOME environment variable is set and points to your JDK installation – Setup M2_HOME to a directory under the windows user directory with a folder called .m2 – Extract distribution archive in any directory – unzip apache-maven-3.3.3-bin.zip – Add the bin directory of the created directory apache-maven-3.3.3 to the PATH environment variable – Confirm with mvn -v in a new shell. The result should look similar to set M2_HOME=c:maven-3.2.x-SNAPSHOT set PATH=%M2_HOME%bin;%PATH%
  • 9. POM • POM stands for "Project Object Model“ • XML representation of a Maven project held in a file named pom.xml
  • 10. Artifact Vector • Each Maven project produces an element, such as a JAR, WAR or EAR, uniquely identified by a composite of fields known as groupId, artifactId, packaging, version and scope. • This vector of fields uniquely distinguishes a Maven artifact from all others. • Many Maven reports and plugins print the details of a specific artifact in this colon separated fashion: groupid:artifactid:packaging:version:scope • An example of this output for the core Spring JAR would be: org.springframework:spring:jar:2.5.6:compile
  • 11. Maven Coordinates • groupId: This is generally unique amongst an organization or a project. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. – Example: The org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo. • artifactId: Name that the project is known by. – Example: my-project lives in $M2_REPO/org/codehaus/mojo/my-project. • packaging: Project’s artifact type. Default value is jar. The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par. These define the default list of goals which execute to each corresponding build lifecycle stage for a particular package structure. • version: Code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. – Example: my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.
  • 12. POM Relationships • Super POM • Inheritance • Aggregation • Properties • Dependencies
  • 13. Super POM Super POM POM1 POM2 POM3 • The Super POM is Maven's default POM. • It is Pseudo-invisible. • All projects inherit it. • Specifies file location defaults. • Locks version of common plugins.
  • 16. Providing a uniform build system Project 1 Project 5 Project 2 Project 3 Project 4 POM & Plugins MAVEN
  • 17. Project Aggregation • Instead of specifying the parent POM from the module, it specifies the modules from the parent POM <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <packaging>pom</packaging> <modules> <module>my-module</module> </modules> </project>
  • 18. Inheritance Aggregation When several Maven projects have similar configurations -- refactor your projects by pulling out those similar configurations and making a parent project. When a group of projects that are built or processed together -- Create a parent project and have that parent project declare those projects as its modules. Let your Maven projects inherit that parent project, and those configurations would then be applied to all of them. Just build the parent and the rest will follow. You can have both Project Inheritance and Project Aggregation at the same time. You'd just have to apply all three rules: • Specify in every child POM who their parent POM is. • Change the parent POMs packaging to the value "pom" . • Specify in the parent POM the directories of its modules (children POMs)
  • 19. Properties • One of the practices that Maven encourages is don't repeat yourself. • Maven allows you to use both your own and pre-defined variables in the POM. They come in 5 different styles— 1) ${ env.X}  ${ env.PATH} 2) ${ java.X}  ${ java.HOME} 3) ${ project.X}  ${ project.version} 4) ${ system.X}  ${ system.offline} 5) ${X}  ${ someVar}
  • 20. Creating a Project via Archetype • $ mvn archetype:generate • Archetype is a Maven project templating toolkit. • An archetype is defined as – an original pattern or model from which all other things of the same kind are made. • You can choose from various templates available. • You can also create your own archetype template.
  • 22. Command to execute-- Directory Structure Created for the project my-app
  • 23. Pom file generated via archetype
  • 24. EXECUTION GROUPS • Maven divides execution into four nested hierarchies. • From most-encompassing to most- specific, • They are: Lifecycles, Phases, Plugins and Goals • Lifecycle - Flow of steps • Phase - A step in a lifecycle • Plugin – Logical grouping and distribution of related goals • Goal - Single executable task
  • 25. THE MVN COMMAND • Maven supplies a Unix shell script and MSDOS batch file named mvn and mvn.bat respectively. • This command is used to start all Maven builds. • Optional parameters are supplied in a space- delimited fashion. mvn clean package jetty:run –Dmaven.test.skip
  • 26. Executing a Phase or Goal • At the command prompt, either a phase or a plugin goal can be requested. • Multiple phases or goals can be specified and are separated by spaces. • Example - mvn compile:compile jar:jar • If you execute a phase, all phases and bound plugin goals up to that point in the lifecycle are also executed. • Example - mvn deploy This example requests the deploy lifecycle phase, which will also execute the verification, compilation, testing and packaging phases.
  • 27. Built-in Maven Lifecycles • Maven ships with three lifecycles; clean, default, and site. • The clean lifecycle is simplistic in nature. It deletes all generated and compiled artifacts in the output directory.
  • 28. • The default lifecycle defines the most commonly used phases for building an application, ranging from compilation of the code to installation of the completed artifacts, such as a JAR, into a remote Maven repository.
  • 30. • The site lifecycle generates a project information web site, and can deploy the artifacts to a specified web server or local path.
  • 31. Build Settings • defaultGoal: the default goal or phase to execute if none is given. • directory: This is the directory where the build will dump its files. • finalName: This is the name of the bundled project when it is finally built.It defaults to ${artifactId}-${version}. • filter: Defines *.properties files that contain a list of properties that apply to resources on build.
  • 32. Resources • Specify where the resource files will be placed in the artifact.
  • 33. Add Resources to JAR Just place the files in the “resources ” folder It is added in JAR under META-INF folder
  • 34. Filter Resources • A resource file may need to contain a value that can only be supplied at build time. • To accomplish this in Maven, put a reference to the property that will contain the value into your resource file using the syntax – ${<property name>} • The property can be one of the values defined in – your pom.xml, – a value defined in the user's settings.xml, – a property defined in an external properties file, – or a system property.
  • 37. Using External Properties File application.name=${pom.name} application.version=${pom.version} message=${my.filter.value} In application.properties my.filter.value=hello! In filter.properties In pom.xml
  • 38. DEPENDENCIES • To express your project’s reliance on a particular artifact, you declare a dependency in the project’s pom.xml.
  • 40. Transitive Dependencies Discovery Feature Description Dependency mediation Determines what version of a dependency is to be used when multiple versions of an artifact are encountered. If two dependency versions are at the same depth in the dependency tree, the first declared dependency will be used. Dependency management Directly specify the versions of artifacts to be used when they are encountered in transitive dependencies. For an example project C can include B as a dependency in its dependencyManagement section and directly control which version of B is to be used when it is ever referenced. Dependency scope Includes dependencies as per the current stage of the build Excluded dependencies Any transitive dependency can be excluede using "exclusion" element. As example, A depends upon B and B depends upon C then A can mark C as excluded. Optional dependencies Any transitive dependency can be marked as optional using "optional" element. As example, A depends upon B and B depends upon C. Now B marked C as optional. Then A will not use C.
  • 42. • Used to pull all the dependency information into a common POM file, simplifying the references in the child POM file. • Used when you have multiple attributes that you don’t want to retype in under multiple children projects. • Used to define a standard version of an artifact to use across multiple projects.
  • 43. VISUALIZE Dependencies • List view ‣ mvn dependency:resolve • Tree view ‣ mvn dependency:tree • Plugin list view ‣ mvn dependency:resolve-plugins
  • 44. Standard Scopes • Each dependency can specify a scope, which controls its visibility and inclusion in the final packaged artifact, such as a WAR or EAR. • Scoping enables you to minimize the JARs that ship with your product.