SlideShare ist ein Scribd-Unternehmen logo
1 von 46
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.
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.
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.
• 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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Maven
MavenMaven
Maven
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
Jenkins
JenkinsJenkins
Jenkins
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Jenkins Introduction
Jenkins IntroductionJenkins Introduction
Jenkins Introduction
 

Ähnlich wie Maven Basics - Explained

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 worldDmitry Bakaleinik
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using MavenScheidt & Bachmann
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to MavenEric Wyles
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsSISTechnologies
 
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 toolRenato Primavera
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeHolasz Kati
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Robert Scholte
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.Fazreil Amreen Abdul Jalil
 

Ähnlich wie Maven Basics - Explained (20)

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
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
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
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven
MavenMaven
Maven
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 
Maven
MavenMaven
Maven
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Maven basics
Maven basicsMaven basics
Maven basics
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
 

Mehr von Smita Prasad

Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional ExplainedSmita Prasad
 
Learn Apache Shiro
Learn Apache ShiroLearn Apache Shiro
Learn Apache ShiroSmita Prasad
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An IntroductionSmita Prasad
 

Mehr von Smita Prasad (6)

Intro to React.js
Intro to React.jsIntro to React.js
Intro to React.js
 
Maven advanced
Maven advancedMaven advanced
Maven advanced
 
Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional Explained
 
Learn Apache Shiro
Learn Apache ShiroLearn Apache Shiro
Learn Apache Shiro
 
Clean code
Clean codeClean code
Clean code
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An Introduction
 

Kürzlich hochgeladen

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Kürzlich hochgeladen (20)

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

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.
  • 14.
  • 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.
  • 21.
  • 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.
  • 29.
  • 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.