Maven

Emprovise
EmproviseEmprovise
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.
Maven
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
1 de 27

Recomendados

Maven Basics - Explained por
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
1.1K visualizações46 slides
Introduction to Maven por
Introduction to MavenIntroduction to Maven
Introduction to MavenMindfire Solutions
962 visualizações22 slides
Maven Introduction por
Maven IntroductionMaven Introduction
Maven IntroductionSandeep Chawla
21.2K visualizações31 slides
Maven Overview por
Maven OverviewMaven Overview
Maven OverviewFastConnect
8.5K visualizações29 slides
Maven tutorial por
Maven tutorialMaven tutorial
Maven tutorialDragos Balan
1.8K visualizações52 slides
Maven por
MavenMaven
MavenVineela Madarapu
980 visualizações19 slides

Mais conteúdo relacionado

Mais procurados

Apache Maven por
Apache MavenApache Maven
Apache MavenRahul Tanwani
2.1K visualizações35 slides
Apache maven 2 overview por
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overviewReturn on Intelligence
1.8K visualizações37 slides
Introduction to Maven por
Introduction to MavenIntroduction to Maven
Introduction to MavenOnkar Deshpande
3.4K visualizações67 slides
Spring Boot por
Spring BootSpring Boot
Spring BootJiayun Zhou
2.5K visualizações110 slides
An Introduction to Maven por
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
13.9K visualizações40 slides
Maven 3 Overview por
Maven 3  OverviewMaven 3  Overview
Maven 3 OverviewMike Ensor
2.7K visualizações22 slides

Mais procurados(20)

Apache Maven por Rahul Tanwani
Apache MavenApache Maven
Apache Maven
Rahul Tanwani2.1K visualizações
Introduction to Maven por Onkar Deshpande
Introduction to MavenIntroduction to Maven
Introduction to Maven
Onkar Deshpande3.4K visualizações
Spring Boot por Jiayun Zhou
Spring BootSpring Boot
Spring Boot
Jiayun Zhou2.5K visualizações
An Introduction to Maven por Vadym Lotar
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar13.9K visualizações
Maven 3 Overview por Mike Ensor
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor2.7K visualizações
Jenkins CI presentation por Jonathan Holloway
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
Jonathan Holloway13.8K visualizações
Ansible presentation por John Lynch
Ansible presentationAnsible presentation
Ansible presentation
John Lynch34.8K visualizações
Spring Boot por HongSeong Jeon
Spring BootSpring Boot
Spring Boot
HongSeong Jeon3.9K visualizações
Spring boot introduction por Rasheed Waraich
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich7.7K visualizações
Introduction to Spring Boot por Purbarun Chakrabarti
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti1.1K visualizações
PUC SE Day 2019 - SpringBoot por Josué Neis
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis701 visualizações
Docker Networking Overview por Sreenivas Makam
Docker Networking OverviewDocker Networking Overview
Docker Networking Overview
Sreenivas Makam21.1K visualizações
Connecting Connect with Spring Boot por Vincent Kok
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
Vincent Kok1.1K visualizações
Docker Advanced registry usage por Docker, Inc.
Docker Advanced registry usageDocker Advanced registry usage
Docker Advanced registry usage
Docker, Inc.8.3K visualizações
Spring boot por Gyanendra Yadav
Spring bootSpring boot
Spring boot
Gyanendra Yadav1.9K visualizações
An introduction to Maven por Joao Pereira
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira7.9K visualizações
Java EE vs Spring Framework por Rohit Kelapure
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework
Rohit Kelapure22.3K visualizações
Introduction to spring boot por Santosh Kumar Kar
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar19.6K visualizações
Spring Boot por Jaran Flaath
Spring BootSpring Boot
Spring Boot
Jaran Flaath545 visualizações

Destaque

Apache Struts 2 Advance por
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 AdvanceEmprovise
3.1K visualizações34 slides
Spring Web Views por
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
2K visualizações42 slides
the cell por
 the cell the cell
the cellDr-HAMDAN
655 visualizações85 slides
Carbohdrates 2013 por
Carbohdrates 2013Carbohdrates 2013
Carbohdrates 2013Dr-HAMDAN
2.7K visualizações49 slides
Enterprise Java Beans 3 - Business Logic por
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
1.6K visualizações57 slides
Spring Web Services por
Spring Web ServicesSpring Web Services
Spring Web ServicesEmprovise
1.4K visualizações44 slides

Destaque(13)

Apache Struts 2 Advance por Emprovise
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
Emprovise3.1K visualizações
Spring Web Views por Emprovise
Spring Web ViewsSpring Web Views
Spring Web Views
Emprovise2K visualizações
the cell por Dr-HAMDAN
 the cell the cell
the cell
Dr-HAMDAN655 visualizações
Carbohdrates 2013 por Dr-HAMDAN
Carbohdrates 2013Carbohdrates 2013
Carbohdrates 2013
Dr-HAMDAN2.7K visualizações
Enterprise Java Beans 3 - Business Logic por Emprovise
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
Emprovise1.6K visualizações
Spring Web Services por Emprovise
Spring Web ServicesSpring Web Services
Spring Web Services
Emprovise1.4K visualizações
EJB3 Advance Features por Emprovise
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
Emprovise2.3K visualizações
lipid clinical importance sdk 2013 por Dr-HAMDAN
 lipid clinical importance sdk 2013 lipid clinical importance sdk 2013
lipid clinical importance sdk 2013
Dr-HAMDAN7.7K visualizações
Spring JMS por Emprovise
Spring JMSSpring JMS
Spring JMS
Emprovise2.3K visualizações
Spring Web Webflow por Emprovise
Spring Web WebflowSpring Web Webflow
Spring Web Webflow
Emprovise3.7K visualizações
Java Servlets por Emprovise
Java ServletsJava Servlets
Java Servlets
Emprovise2.1K visualizações
Post trans mod-and_protein sorting por Dr-HAMDAN
Post trans mod-and_protein sortingPost trans mod-and_protein sorting
Post trans mod-and_protein sorting
Dr-HAMDAN4.4K visualizações
Effective java por Emprovise
Effective javaEffective java
Effective java
Emprovise2.4K visualizações

Similar a Maven

Maven Presentation - SureFire vs FailSafe por
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeHolasz Kati
1.4K visualizações39 slides
Maven in mulesoft por
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
142 visualizações12 slides
Maven 2 features por
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
4.4K visualizações33 slides
Apache maven, a software project management tool por
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
1.6K visualizações57 slides
Maven por
MavenMaven
MavenHarshit Choudhary
71 visualizações38 slides
Introduction to maven por
Introduction to mavenIntroduction to maven
Introduction to mavenManos Georgopoulos
1.2K visualizações24 slides

Similar a Maven(20)

Maven Presentation - SureFire vs FailSafe por Holasz Kati
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati1.4K visualizações
Maven in mulesoft por venkata20k
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k142 visualizações
Maven 2 features por Angel Ruiz
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz4.4K visualizações
Apache maven, a software project management tool por Renato Primavera
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera1.6K visualizações
Introduction to maven por Manos Georgopoulos
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações
Introduction to maven, its configuration, lifecycle and relationship to JS world por Dmitry Bakaleinik
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik691 visualizações
Mavennotes.pdf por AnkurSingh656748
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh65674810 visualizações
Intelligent Projects with Maven - DevFest Istanbul por Mert Çalışkan
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan1.3K visualizações
Maven 2.0 - Project management and comprehension tool por elliando dias
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
elliando dias2K visualizações
What is maven por sureshraj43
What is mavenWhat is maven
What is maven
sureshraj4395 visualizações
Maven with Flex por Priyank
Maven with FlexMaven with Flex
Maven with Flex
Priyank518 visualizações
Maven with Flex por Priyank
Maven with FlexMaven with Flex
Maven with Flex
Priyank1.1K visualizações
Mavenppt por Surekha Achanta
MavenpptMavenppt
Mavenppt
Surekha Achanta840 visualizações
Maven por Nishant Arora
MavenMaven
Maven
Nishant Arora98 visualizações
Maven nutshell por Valerio Capozio
Maven nutshellMaven nutshell
Maven nutshell
Valerio Capozio1.8K visualizações
BMO - Intelligent Projects with Maven por Mert Çalışkan
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan1.6K visualizações
Maven por Shraddha
MavenMaven
Maven
Shraddha416 visualizações
Build Automation using Maven por Ankit Gubrani
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
Ankit Gubrani3.7K visualizações

Mais de Emprovise

Secure socket layer por
Secure socket layerSecure socket layer
Secure socket layerEmprovise
149 visualizações26 slides
EJB3 Basics por
EJB3 BasicsEJB3 Basics
EJB3 BasicsEmprovise
13.6K visualizações42 slides
RESTful WebServices por
RESTful WebServicesRESTful WebServices
RESTful WebServicesEmprovise
773 visualizações2 slides
J2EE Patterns por
J2EE PatternsJ2EE Patterns
J2EE PatternsEmprovise
3.1K visualizações77 slides
JMS por
JMSJMS
JMSEmprovise
1.7K visualizações61 slides
Spring MVC por
Spring MVCSpring MVC
Spring MVCEmprovise
2.4K visualizações55 slides

Mais de Emprovise(13)

Secure socket layer por Emprovise
Secure socket layerSecure socket layer
Secure socket layer
Emprovise149 visualizações
EJB3 Basics por Emprovise
EJB3 BasicsEJB3 Basics
EJB3 Basics
Emprovise13.6K visualizações
RESTful WebServices por Emprovise
RESTful WebServicesRESTful WebServices
RESTful WebServices
Emprovise773 visualizações
J2EE Patterns por Emprovise
J2EE PatternsJ2EE Patterns
J2EE Patterns
Emprovise3.1K visualizações
JMS por Emprovise
JMSJMS
JMS
Emprovise1.7K visualizações
Spring MVC por Emprovise
Spring MVCSpring MVC
Spring MVC
Emprovise2.4K visualizações
Enterprise Spring por Emprovise
Enterprise SpringEnterprise Spring
Enterprise Spring
Emprovise768 visualizações
Spring Basics por Emprovise
Spring BasicsSpring Basics
Spring Basics
Emprovise1.3K visualizações
Apache Struts 2 Framework por Emprovise
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
Emprovise4.2K visualizações
Java Advance Concepts por Emprovise
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
Emprovise837 visualizações
Java Basics por Emprovise
Java BasicsJava Basics
Java Basics
Emprovise1.5K visualizações
Object Oriented Principles por Emprovise
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
Emprovise1K visualizações
GWT Basics por Emprovise
GWT BasicsGWT Basics
GWT Basics
Emprovise1.7K visualizações

Último

Nelson_RecordStore.pdf por
Nelson_RecordStore.pdfNelson_RecordStore.pdf
Nelson_RecordStore.pdfBrynNelson5
50 visualizações10 slides
Introduction to AERO Supply Chain - #BEAERO Trainning program por
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning programGuennoun Wajih
123 visualizações78 slides
StudioX.pptx por
StudioX.pptxStudioX.pptx
StudioX.pptxNikhileshSathyavarap
106 visualizações18 slides
Monthly Information Session for MV Asterix (November) por
Monthly Information Session for MV Asterix (November)Monthly Information Session for MV Asterix (November)
Monthly Information Session for MV Asterix (November)Esquimalt MFRC
213 visualizações26 slides
11.30.23A Poverty and Inequality in America.pptx por
11.30.23A Poverty and Inequality in America.pptx11.30.23A Poverty and Inequality in America.pptx
11.30.23A Poverty and Inequality in America.pptxmary850239
181 visualizações18 slides
Guess Papers ADC 1, Karachi University por
Guess Papers ADC 1, Karachi UniversityGuess Papers ADC 1, Karachi University
Guess Papers ADC 1, Karachi UniversityKhalid Aziz
105 visualizações17 slides

Último(20)

Nelson_RecordStore.pdf por BrynNelson5
Nelson_RecordStore.pdfNelson_RecordStore.pdf
Nelson_RecordStore.pdf
BrynNelson550 visualizações
Introduction to AERO Supply Chain - #BEAERO Trainning program por Guennoun Wajih
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning program
Guennoun Wajih123 visualizações
Monthly Information Session for MV Asterix (November) por Esquimalt MFRC
Monthly Information Session for MV Asterix (November)Monthly Information Session for MV Asterix (November)
Monthly Information Session for MV Asterix (November)
Esquimalt MFRC213 visualizações
11.30.23A Poverty and Inequality in America.pptx por mary850239
11.30.23A Poverty and Inequality in America.pptx11.30.23A Poverty and Inequality in America.pptx
11.30.23A Poverty and Inequality in America.pptx
mary850239181 visualizações
Guess Papers ADC 1, Karachi University por Khalid Aziz
Guess Papers ADC 1, Karachi UniversityGuess Papers ADC 1, Karachi University
Guess Papers ADC 1, Karachi University
Khalid Aziz105 visualizações
NodeJS and ExpressJS.pdf por ArthyR3
NodeJS and ExpressJS.pdfNodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdf
ArthyR350 visualizações
JRN 362 - Lecture Twenty-Three (Epilogue) por Rich Hanley
JRN 362 - Lecture Twenty-Three (Epilogue)JRN 362 - Lecture Twenty-Three (Epilogue)
JRN 362 - Lecture Twenty-Three (Epilogue)
Rich Hanley43 visualizações
UNIDAD 3 6º C.MEDIO.pptx por MarcosRodriguezUcedo
UNIDAD 3 6º C.MEDIO.pptxUNIDAD 3 6º C.MEDIO.pptx
UNIDAD 3 6º C.MEDIO.pptx
MarcosRodriguezUcedo150 visualizações
EILO EXCURSION PROGRAMME 2023 por info33492
EILO EXCURSION PROGRAMME 2023EILO EXCURSION PROGRAMME 2023
EILO EXCURSION PROGRAMME 2023
info33492208 visualizações
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx por Niranjan Chavan
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptxGuidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Guidelines & Identification of Early Sepsis DR. NN CHAVAN 02122023.pptx
Niranjan Chavan42 visualizações
REFERENCING, CITATION.pptx por abhisrivastava11
REFERENCING, CITATION.pptxREFERENCING, CITATION.pptx
REFERENCING, CITATION.pptx
abhisrivastava1141 visualizações
JQUERY.pdf por ArthyR3
JQUERY.pdfJQUERY.pdf
JQUERY.pdf
ArthyR3107 visualizações
Education of marginalized and socially disadvantages segments.pptx por GarimaBhati5
Education of marginalized and socially disadvantages segments.pptxEducation of marginalized and socially disadvantages segments.pptx
Education of marginalized and socially disadvantages segments.pptx
GarimaBhati547 visualizações
MIXING OF PHARMACEUTICALS.pptx por Anupkumar Sharma
MIXING OF PHARMACEUTICALS.pptxMIXING OF PHARMACEUTICALS.pptx
MIXING OF PHARMACEUTICALS.pptx
Anupkumar Sharma125 visualizações
MercerJesse3.0.pdf por jessemercerail
MercerJesse3.0.pdfMercerJesse3.0.pdf
MercerJesse3.0.pdf
jessemercerail163 visualizações
Six Sigma Concept by Sahil Srivastava.pptx por Sahil Srivastava
Six Sigma Concept by Sahil Srivastava.pptxSix Sigma Concept by Sahil Srivastava.pptx
Six Sigma Concept by Sahil Srivastava.pptx
Sahil Srivastava51 visualizações
What is Digital Transformation? por Mark Brown
What is Digital Transformation?What is Digital Transformation?
What is Digital Transformation?
Mark Brown41 visualizações
Creative Restart 2023: Atila Martins - Craft: A Necessity, Not a Choice por Taste
Creative Restart 2023: Atila Martins - Craft: A Necessity, Not a ChoiceCreative Restart 2023: Atila Martins - Craft: A Necessity, Not a Choice
Creative Restart 2023: Atila Martins - Craft: A Necessity, Not a Choice
Taste52 visualizações
Pharmaceutical Analysis PPT (BP 102T) por yakshpharmacy009
Pharmaceutical Analysis PPT (BP 102T) Pharmaceutical Analysis PPT (BP 102T)
Pharmaceutical Analysis PPT (BP 102T)
yakshpharmacy009116 visualizações

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.
  • 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