SlideShare a Scribd company logo
1 of 27
Rise of Automated Builds and Deployments
A build tool such as Ant is focused solely on
preprocessing, compilation, packaging, testing, and
distribution.
Maven is a project management tool which
provides a superset of features found in a build
tool.
Maven provides build capabilities, and can run
reports, generate a web site, and facilitate
communication among members of a working
team.
Maven is a project management tool which
encompasses a project object model, a set of
standards, a project lifecycle, a dependency
management system, and logic for executing plugin
goals at defined phases in a lifecycle.
Maven incorporates convention over configuration
concept by providing sensible default behavior for
projects.
Source code is assumed to be in
${basedir}/src/main/java
Resources are assumed to be in
${basedir}/src/main/resources
Tests are assumed to be in ${basedir}/src/test
The byte code is compiled to
${basedir}/target/classes and then a distributable
JAR file is created in ${basedir}/target.
Intelligence of Maven is implemented in the
plugins which are retrieved from the Maven
Repository.
The fact that Maven retrieves both
dependencies and plugins from the remote
repository allows for universal reuse of build
logic.
Maven has abstracted common build tasks into
plugins which are maintained centrally and
shared universally.
Maven maintains a model of a project with
description of the attributes of the project.
Dependency Management: A project is defined by a
unique set of coordinates consisting of a group
identifier, an artifact identifier, and a version, enabling
the coordinates to declare dependencies.
Remote Repositories: Coordinates defined in the Maven
Project Object Model (POM) can be used to create
repositories of Maven artifacts.
Universal Reuse of Build Logic: Plugins contain logic that
works with the descriptive data and configuration
parameters defined in Project Object Model (POM).
Tool Portability / Integration: Maven has standardized
the Project description maintained in the IDE, and while
each IDE continues to maintain custom project
files, they can be easily generated from the model.
Easy Searching and Filtering of Project Artifacts: Tools
like Nexus allow you to index and search the contents of
a repository using the information stored in the POM.
Create a simple pom.xml as follows:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
</project>
Place your source code in
${basedir}/src/main/java
Run mvn install from the command line.
Run mvn site and then find an index.html file in
target/site that contains links to JavaDoc and a few
reports about your source code.
Ant doesn't have formal conventions like a
common project directory structure or default
behavior.
Ant is procedural
Ant doesn't have a lifecycle, with goals and
sequence of tasks defined for each goal manually.
Maven has conventions. It knows where your
source code is because you followed the
convention.
Maven is declarative. A pom.xml file is created and
put into the source in the default directory.
Maven has a lifecycle which was invoked when
you executed mvn install. The command tells
Maven to execute a series of sequential lifecycle
phases until it reached the install lifecycle phase.
Once Maven is unpacked to the installation directory, the two
environment variables —PATH and M2_HOME need to be
set.
To set these environment variables from the command-line, type in
the following Windows commands:
set M2_HOME=c:Program Filesapache-maven-2.2.1
set PATH=%PATH%;%M2_HOME%bin
Corresponding Linux Commands:
cd /usr/local
ln -s apache-maven-2.2.1 maven
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
Check the version by running mvn -v from the command-line.
~/.m2/settings.xml contains user-specific configuration for
authentication, repositories and other information.
~/.m2/repository/ contains the local Maven repository.
To start a new Maven project, use the Maven
Archetype plugin from the command line.
$ mvn archetype:generate -
DgroupId=org.sonatype.mavenbook.simple 
-DartifactId=simple 
-DpackageName=org.sonatype.mavenbook 
-Dversion=1.0-SNAPSHOT
archetype:generate is called a Maven goal.
The -Dname=value pairs are arguments that are
passed to the goal and take the form of -D
properties.
The plugin is the prefix archetype, and the goal is
generate.
The project is installed using the “mvn install”
command.
The Maven Archetype plugin creates a directory simple/
that matches the artifactId, known as the project’s base
directory.
Every Maven project has a Project Object Model (POM)
in pom.xml which describes the project, configures
plugins, and declares dependencies.
All the project's source code and resources are placed
under src/main.
In a Java project, Java classes are placed in
src/main/java and classpath resources are placed in
src/main/resources.
The test cases for the project are located in src/test.
All tests are placed in src/test/java, and classpath
resources for tests are located in src/test/resources.
The first few elements in POM—groupId, artifactId, packaging,
version—are known as the Maven coordinates which uniquely
identify a project.
name and url are descriptive elements of the POM providing a
human readable name and associating the project with a web
site.
The dependencies element defines a single, test-scoped
dependency on a unit testing framework
Maven always executes against an effective POM, a
combination of settings from the project's pom.xml, all parent
POMs, a super-POM defined within Maven, user-defined
settings, and active profiles.
All projects ultimately extend the super-POM, which defines a
set of sensible default configuration settings.
The "effective" POM can be seen (with the contents of the
project's POM interpolated with the contents of all parent
POMs, user settings, and any active profiles) using the
command:
$ mvn help:effective-pom
A Maven Plugin is a collection of one or more
goals.
Maven also provides for the ability to define
custom plugins.
Maven plugins can be simple core plugins like
the Jar plugin, which contains goals for creating
JAR files, Compiler plugin, which contains goals
for compiling source code and unit tests, or the
Surefire plugin, which contains goals for
executing unit tests and generating reports.
A goal is a specific task that may be executed as a
standalone goal or along with other goals as part
of a larger build.
A goal is a “unit of work” in Maven.
The compile goal in the Compiler plugin, compiles
all of the source code for a project.
Goals are configured via configuration properties
that can be used to customize behavior.
When referring to a plugin goal, we frequently use
the shorthand notation, pluginId:goalId similar to
archetype:generate.
Goals define parameters that can define sensible
default values.
The command “mvn install” doesn’t specify a plugin
goal but specifies a Maven lifecycle phase.
A phase is a step in what Maven calls the “build
lifecycle” which is an ordered sequence of phases
involved in building a project.
Maven can support a number of different
lifecycles, but the one that’s most often used is the
default Maven lifecycle, which begins with a phase
to validate the basic integrity of the project and
ends with a phase that involves deploying a project
to production.
Plugin goals can be attached to a lifecycle phase.
As Maven moves through the phases in a lifecycle, it
will execute the goals attached to each particular
phase.
Each phase may have zero or more goals bound to it
When “mvn install” reached the package phase, it
executed the jar goal in the Jar plugin.
Since the simple Quickstart project has (by default) a jar
packaging type, the jar:jar goal is bound to the package
phase.
The preceding goals are executed as Maven steps
through the phases preceding package in the Maven
lifecycle; executing a phase will first execute all
preceding phases in order, ending with the phase
specified on the command line.
Each phase corresponds to zero or more goals, and as
no plugin configuration or customization is performed.
When Maven executes a goal, each goal has access
to the information defined in a project’s POM.
Goals execute in the context of a POM.
Goals are actions we wish to take upon a
project, and a project is defined by a POM.
The POM names the project, provides a set of
unique identifiers (coordinates) for a project, and
defines the relationships between this project and
others through dependencies, parents, and
prerequisites.
Maven coordinates define a set of identifiers which
can be used to uniquely identify a project, a
dependency, or a plugin in a Maven POM.
The combined identifiers: the
groupId, artifactId, version and packaging make up the
project’s maven coordinates.
Maven pinpoints a project via its coordinates when one
project relates to another, either as a dependency, a
plugin, or a parent project reference.
groupId: The
group, company, team, organization, project, or other
group. It begins with reverse domain name of org.
artifactId: A unique identifier under groupId that
represents a single project.
version: A specific release of a project.
packaging: The type of project, defaulting to
jar, describing the packaged output produced by a
project. This is not a part of a project's unique identifier.
A repository is a collection of project artifacts
stored in a directory structure that closely
matches a project's Maven coordinates.
The standard for a Maven repository is to store
an artifact in the following directory relative to
the root of the repository:
/<groupId>/<artifactId>/<version>/<artifactId>-
<version>.<packaging>.
Maven always looks up for the artifact in the
local repository before downloading it from the
remote Maven repository.
Maven downloads POM files for dependency in
addition to artifacts on order to support transitive
dependencies.
Maven adds all the dependencies of the library to
the project’s dependencies implicitly resolving
conflicts with default behavior.
The POM file declares dependencies on other
artifacts which are called transitive dependencies.
Maven also provides for different dependency
scopes limiting its availability for particular goals.
The provided scope tells Maven that a dependency
is needed for compilation, but should not be
bundled with the output of a build.
Create a basic skeleton of project using Maven
Archetype using mvn archetype:generate command.
Configure the Maven Compiler plugin to target Java 5
using the POM.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
Add Organizational, Legal, and Developer
Information to the pom.xml.
Add project dependencies
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependencies>
The http://repository.sonatype.org contains some
dependency libraries.
Add new packages (directories) in project's
source code location stored in src/main/java.
Add resources to the default package (or in root
of the classpath) such as ‘src/main/resources’.
The program is executed using the Exec plugin
from the Codehaus Mojo project.
mvn install
mvn exec:java -
Dexec.mainClass=org.sonatype.mavenbook.we
ather.Main
Add unit tests to the src/test/java folder.
The Exec plugin allows you to execute Java classes and
other scripts.
It is not a core Maven plugin, but it is available from the
Mojo project hosted by Codehaus.
Description of the plugin can be found by:
mvn help:describe -Dplugin=exec –Dfull
To find out what is on the classpath, the Maven
Dependency plugin can be used to print out a list of
resolved dependencies.
mvn dependency:resolve
mvn dependency:tree
To see the full dependency trail, including rejected
artifacts:
mvn install -X
A test-scoped dependency is a dependency that is
available on the classpath only during test compilation
and test execution.
If the project has war or ear packaging, a test-scoped
dependency would not be included in the project’s
output archive.
To add a test-scoped dependency, add the dependency
element to the project’s dependencies section in the
POM file.
run mvn dependency:resolve to see the dependency
element listed as a dependency with scope test.
Add the test resources in the src/test/resources
directory.
The test phase run for the mvn package or mvn install
commands, along with mvn test which runs all the
lifecycle phases up test phase.
When Maven encounters a build failure, its default behavior is to
stop the current build.
To continue building a project even when the Surefire plugin
encounters failed test cases, the testFailureIgnore configuration
property of the Surefire plugin should be set to true.
mvn test -Dmaven.test.failure.ignore=true
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skip>true</skip>
</configuration>
</plugin>
To skip the unit tests, the maven.test.skip properties should be set to
true.
mvn install -Dmaven.test.skip=true
The Maven Assembly plugin is a plugin to create arbitrary
distributions for applications.
It can be used to assemble the output of any project in any format by
defining a custom assembly descriptor.
<project> [...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
[...]</project>
Command to build the assembly: mvn install assembly:assembly

More Related Content

What's hot

Jenkins for java world
Jenkins for java worldJenkins for java world
Jenkins for java worldAshok Kumar
 
Getting started with Jenkins
Getting started with JenkinsGetting started with Jenkins
Getting started with JenkinsEdureka!
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkinsAbe Diaz
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To JenkinsKnoldus Inc.
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017Docker, Inc.
 
What is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | EdurekaWhat is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | EdurekaEdureka!
 
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...SlideTeam
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandTroublemaker Khunpech
 
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and OpsKubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and OpsTomasz Cholewa
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & ActuatorsVMware Tanzu
 

What's hot (20)

Jenkins for java world
Jenkins for java worldJenkins for java world
Jenkins for java world
 
Getting started with Jenkins
Getting started with JenkinsGetting started with Jenkins
Getting started with Jenkins
 
Jenkins-CI
Jenkins-CIJenkins-CI
Jenkins-CI
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
 
Jenkins
JenkinsJenkins
Jenkins
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To Jenkins
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017
 
What is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | EdurekaWhat is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | Edureka
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...
Guide To Jenkins Management Continuous Integration And Useful Plugins Complet...
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
 
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and OpsKubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 

Viewers also liked

Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 AdvanceEmprovise
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
 
Carbohdrates 2013
Carbohdrates 2013Carbohdrates 2013
Carbohdrates 2013Dr-HAMDAN
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web ServicesEmprovise
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 
lipid clinical importance sdk 2013
 lipid clinical importance sdk 2013 lipid clinical importance sdk 2013
lipid clinical importance sdk 2013Dr-HAMDAN
 
Spring Web Webflow
Spring Web WebflowSpring Web Webflow
Spring Web WebflowEmprovise
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Post trans mod-and_protein sorting
Post trans mod-and_protein sortingPost trans mod-and_protein sorting
Post trans mod-and_protein sortingDr-HAMDAN
 
Effective java
Effective javaEffective java
Effective javaEmprovise
 

Viewers also liked (13)

Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
the cell
 the cell the cell
the cell
 
Carbohdrates 2013
Carbohdrates 2013Carbohdrates 2013
Carbohdrates 2013
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web Services
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
lipid clinical importance sdk 2013
 lipid clinical importance sdk 2013 lipid clinical importance sdk 2013
lipid clinical importance sdk 2013
 
Spring JMS
Spring JMSSpring JMS
Spring JMS
 
Spring Web Webflow
Spring Web WebflowSpring Web Webflow
Spring Web Webflow
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Post trans mod-and_protein sorting
Post trans mod-and_protein sortingPost trans mod-and_protein sorting
Post trans mod-and_protein sorting
 
Effective java
Effective javaEffective java
Effective java
 

Similar to Maven

Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeHolasz Kati
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel 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 toolRenato Primavera
 
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
 
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
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolelliando dias
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
 

Similar to Maven (20)

Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
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
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 
What is maven
What is mavenWhat is maven
What is maven
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven
MavenMaven
Maven
 
Maven nutshell
Maven nutshellMaven nutshell
Maven nutshell
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Maven
MavenMaven
Maven
 

More from Emprovise

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Emprovise
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessEmprovise
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layerEmprovise
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServicesEmprovise
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE PatternsEmprovise
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise SpringEmprovise
 
Spring Basics
Spring BasicsSpring Basics
Spring BasicsEmprovise
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 FrameworkEmprovise
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance ConceptsEmprovise
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesEmprovise
 

More from Emprovise (15)

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/Business
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layer
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServices
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE Patterns
 
JMS
JMSJMS
JMS
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise Spring
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
GWT Basics
GWT BasicsGWT Basics
GWT Basics
 

Recently uploaded

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

Maven

  • 1. Rise of Automated Builds and Deployments
  • 2. A build tool such as Ant is focused solely on preprocessing, compilation, packaging, testing, and distribution. Maven is a project management tool which provides a superset of features found in a build tool. Maven provides build capabilities, and can run reports, generate a web site, and facilitate communication among members of a working team. Maven is a project management tool which encompasses a project object model, a set of standards, a project lifecycle, a dependency management system, and logic for executing plugin goals at defined phases in a lifecycle.
  • 3. Maven incorporates convention over configuration concept by providing sensible default behavior for projects. Source code is assumed to be in ${basedir}/src/main/java Resources are assumed to be in ${basedir}/src/main/resources Tests are assumed to be in ${basedir}/src/test The byte code is compiled to ${basedir}/target/classes and then a distributable JAR file is created in ${basedir}/target.
  • 4. Intelligence of Maven is implemented in the plugins which are retrieved from the Maven Repository. The fact that Maven retrieves both dependencies and plugins from the remote repository allows for universal reuse of build logic. Maven has abstracted common build tasks into plugins which are maintained centrally and shared universally. Maven maintains a model of a project with description of the attributes of the project.
  • 5. Dependency Management: A project is defined by a unique set of coordinates consisting of a group identifier, an artifact identifier, and a version, enabling the coordinates to declare dependencies. Remote Repositories: Coordinates defined in the Maven Project Object Model (POM) can be used to create repositories of Maven artifacts. Universal Reuse of Build Logic: Plugins contain logic that works with the descriptive data and configuration parameters defined in Project Object Model (POM). Tool Portability / Integration: Maven has standardized the Project description maintained in the IDE, and while each IDE continues to maintain custom project files, they can be easily generated from the model. Easy Searching and Filtering of Project Artifacts: Tools like Nexus allow you to index and search the contents of a repository using the information stored in the POM.
  • 6. Create a simple pom.xml as follows: <project> <modelVersion>4.0.0</modelVersion> <groupId>org.sonatype.mavenbook</groupId> <artifactId>my-project</artifactId> <version>1.0</version> </project> Place your source code in ${basedir}/src/main/java Run mvn install from the command line. Run mvn site and then find an index.html file in target/site that contains links to JavaDoc and a few reports about your source code.
  • 7. Ant doesn't have formal conventions like a common project directory structure or default behavior. Ant is procedural Ant doesn't have a lifecycle, with goals and sequence of tasks defined for each goal manually. Maven has conventions. It knows where your source code is because you followed the convention. Maven is declarative. A pom.xml file is created and put into the source in the default directory. Maven has a lifecycle which was invoked when you executed mvn install. The command tells Maven to execute a series of sequential lifecycle phases until it reached the install lifecycle phase.
  • 8. Once Maven is unpacked to the installation directory, the two environment variables —PATH and M2_HOME need to be set. To set these environment variables from the command-line, type in the following Windows commands: set M2_HOME=c:Program Filesapache-maven-2.2.1 set PATH=%PATH%;%M2_HOME%bin Corresponding Linux Commands: cd /usr/local ln -s apache-maven-2.2.1 maven export M2_HOME=/usr/local/maven export PATH=${M2_HOME}/bin:${PATH} Check the version by running mvn -v from the command-line. ~/.m2/settings.xml contains user-specific configuration for authentication, repositories and other information. ~/.m2/repository/ contains the local Maven repository.
  • 9. To start a new Maven project, use the Maven Archetype plugin from the command line. $ mvn archetype:generate - DgroupId=org.sonatype.mavenbook.simple -DartifactId=simple -DpackageName=org.sonatype.mavenbook -Dversion=1.0-SNAPSHOT archetype:generate is called a Maven goal. The -Dname=value pairs are arguments that are passed to the goal and take the form of -D properties. The plugin is the prefix archetype, and the goal is generate. The project is installed using the “mvn install” command.
  • 10. The Maven Archetype plugin creates a directory simple/ that matches the artifactId, known as the project’s base directory. Every Maven project has a Project Object Model (POM) in pom.xml which describes the project, configures plugins, and declares dependencies. All the project's source code and resources are placed under src/main. In a Java project, Java classes are placed in src/main/java and classpath resources are placed in src/main/resources. The test cases for the project are located in src/test. All tests are placed in src/test/java, and classpath resources for tests are located in src/test/resources.
  • 11. The first few elements in POM—groupId, artifactId, packaging, version—are known as the Maven coordinates which uniquely identify a project. name and url are descriptive elements of the POM providing a human readable name and associating the project with a web site. The dependencies element defines a single, test-scoped dependency on a unit testing framework Maven always executes against an effective POM, a combination of settings from the project's pom.xml, all parent POMs, a super-POM defined within Maven, user-defined settings, and active profiles. All projects ultimately extend the super-POM, which defines a set of sensible default configuration settings. The "effective" POM can be seen (with the contents of the project's POM interpolated with the contents of all parent POMs, user settings, and any active profiles) using the command: $ mvn help:effective-pom
  • 12. A Maven Plugin is a collection of one or more goals. Maven also provides for the ability to define custom plugins. Maven plugins can be simple core plugins like the Jar plugin, which contains goals for creating JAR files, Compiler plugin, which contains goals for compiling source code and unit tests, or the Surefire plugin, which contains goals for executing unit tests and generating reports.
  • 13. A goal is a specific task that may be executed as a standalone goal or along with other goals as part of a larger build. A goal is a “unit of work” in Maven. The compile goal in the Compiler plugin, compiles all of the source code for a project. Goals are configured via configuration properties that can be used to customize behavior. When referring to a plugin goal, we frequently use the shorthand notation, pluginId:goalId similar to archetype:generate. Goals define parameters that can define sensible default values.
  • 14. The command “mvn install” doesn’t specify a plugin goal but specifies a Maven lifecycle phase. A phase is a step in what Maven calls the “build lifecycle” which is an ordered sequence of phases involved in building a project. Maven can support a number of different lifecycles, but the one that’s most often used is the default Maven lifecycle, which begins with a phase to validate the basic integrity of the project and ends with a phase that involves deploying a project to production. Plugin goals can be attached to a lifecycle phase. As Maven moves through the phases in a lifecycle, it will execute the goals attached to each particular phase. Each phase may have zero or more goals bound to it
  • 15. When “mvn install” reached the package phase, it executed the jar goal in the Jar plugin. Since the simple Quickstart project has (by default) a jar packaging type, the jar:jar goal is bound to the package phase. The preceding goals are executed as Maven steps through the phases preceding package in the Maven lifecycle; executing a phase will first execute all preceding phases in order, ending with the phase specified on the command line. Each phase corresponds to zero or more goals, and as no plugin configuration or customization is performed.
  • 16.
  • 17. When Maven executes a goal, each goal has access to the information defined in a project’s POM. Goals execute in the context of a POM. Goals are actions we wish to take upon a project, and a project is defined by a POM. The POM names the project, provides a set of unique identifiers (coordinates) for a project, and defines the relationships between this project and others through dependencies, parents, and prerequisites. Maven coordinates define a set of identifiers which can be used to uniquely identify a project, a dependency, or a plugin in a Maven POM.
  • 18. The combined identifiers: the groupId, artifactId, version and packaging make up the project’s maven coordinates. Maven pinpoints a project via its coordinates when one project relates to another, either as a dependency, a plugin, or a parent project reference. groupId: The group, company, team, organization, project, or other group. It begins with reverse domain name of org. artifactId: A unique identifier under groupId that represents a single project. version: A specific release of a project. packaging: The type of project, defaulting to jar, describing the packaged output produced by a project. This is not a part of a project's unique identifier.
  • 19. A repository is a collection of project artifacts stored in a directory structure that closely matches a project's Maven coordinates. The standard for a Maven repository is to store an artifact in the following directory relative to the root of the repository: /<groupId>/<artifactId>/<version>/<artifactId>- <version>.<packaging>. Maven always looks up for the artifact in the local repository before downloading it from the remote Maven repository.
  • 20. Maven downloads POM files for dependency in addition to artifacts on order to support transitive dependencies. Maven adds all the dependencies of the library to the project’s dependencies implicitly resolving conflicts with default behavior. The POM file declares dependencies on other artifacts which are called transitive dependencies. Maven also provides for different dependency scopes limiting its availability for particular goals. The provided scope tells Maven that a dependency is needed for compilation, but should not be bundled with the output of a build.
  • 21. Create a basic skeleton of project using Maven Archetype using mvn archetype:generate command. Configure the Maven Compiler plugin to target Java 5 using the POM. <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build>
  • 22. Add Organizational, Legal, and Developer Information to the pom.xml. Add project dependencies <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependencies> The http://repository.sonatype.org contains some dependency libraries.
  • 23. Add new packages (directories) in project's source code location stored in src/main/java. Add resources to the default package (or in root of the classpath) such as ‘src/main/resources’. The program is executed using the Exec plugin from the Codehaus Mojo project. mvn install mvn exec:java - Dexec.mainClass=org.sonatype.mavenbook.we ather.Main Add unit tests to the src/test/java folder.
  • 24. The Exec plugin allows you to execute Java classes and other scripts. It is not a core Maven plugin, but it is available from the Mojo project hosted by Codehaus. Description of the plugin can be found by: mvn help:describe -Dplugin=exec –Dfull To find out what is on the classpath, the Maven Dependency plugin can be used to print out a list of resolved dependencies. mvn dependency:resolve mvn dependency:tree To see the full dependency trail, including rejected artifacts: mvn install -X
  • 25. A test-scoped dependency is a dependency that is available on the classpath only during test compilation and test execution. If the project has war or ear packaging, a test-scoped dependency would not be included in the project’s output archive. To add a test-scoped dependency, add the dependency element to the project’s dependencies section in the POM file. run mvn dependency:resolve to see the dependency element listed as a dependency with scope test. Add the test resources in the src/test/resources directory. The test phase run for the mvn package or mvn install commands, along with mvn test which runs all the lifecycle phases up test phase.
  • 26. When Maven encounters a build failure, its default behavior is to stop the current build. To continue building a project even when the Surefire plugin encounters failed test cases, the testFailureIgnore configuration property of the Surefire plugin should be set to true. mvn test -Dmaven.test.failure.ignore=true <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> <skip>true</skip> </configuration> </plugin> To skip the unit tests, the maven.test.skip properties should be set to true. mvn install -Dmaven.test.skip=true
  • 27. The Maven Assembly plugin is a plugin to create arbitrary distributions for applications. It can be used to assemble the output of any project in any format by defining a custom assembly descriptor. <project> [...] <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> [...]</project> Command to build the assembly: mvn install assembly:assembly