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 (20)

Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Spring boot
Spring bootSpring boot
Spring boot
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 

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
 
Maven
MavenMaven
Maven
 
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
 
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

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

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