SlideShare a Scribd company logo
Introduction to
Maven
Manolis Georgopoulos
http://manolis.hemera.mobi
20/09/2013
“Maven” what ?
Official site says that:
“Apache Maven is a software project management
and comprehension tool. Based on the concept of a
project object model (POM), Maven can manage a
project's build, reporting and documentation from a
central piece of information.”
…What ???????
Maven is :
o A top-level open source Apache Software Foundation project
o A popular build tool
o A dependency management tool
o A release management tool
The picture describes the Maven
operation and interaction model.
Why Maven?
• Dependency management
• Modularity
• Code reusability
• Abstraction of Build process (no dependency on
IDEs)
• Automated processes (deployments, unit &
integration tests, etc)
Project Structure
src/main/java: Your Java source code goes here
src/main/resources: Other resources your application needs. All
directories or files placed within the src/main/resources directory are
packaged in your JAR with the exact same structure, starting at the
base of the JAR
src/main/filters: Resource filters, in the form of properties files, which
may be used to define variables only known at runtime
src/main/config: Configuration files. The
directory [src/main/config] doesn't show up on the classpath so the
application or test classes can't read anything in it.
src/main/webapp: The Web application directory for a WAR project
src/test/java: Unit tests (will not be deployed)
src/test/resources: Resources to be used for unit tests, but will not be
deployed
src/test/filters: Resources filters to be used for unit tests, but will not
be deployed
src/site: Files used to generate the Maven project Website
Key Concepts
 POM
 Artifacts
 Dependencies
 Lifecycle phases
 Plugins
 Profiles
POM
• POM
o Stands for Project Object Model
o Is Maven’s description of a single project
o Is an XML document
o Contains a detailed description of your project, including information
about versioning and configuration management, dependencies,
application and testing resources, team members and structure, and
much more
POM basic elements
• project – the top level element
• modelVersion - the version of the object model
• groupId – indicates the unique identifier of the organization or group that
created the project
• artifactId – indicates the unique name of the primary artifact being
generated by this project
• packaging – indicates the package type to be used by this artifact (jar,
war, ear, etc). Default value is jar
• version – indicates the version of the artifact generated by the project
• name – indicates the display name used for the project
• url – indicates where the project’s site can be found
• description – provides a basic description for the project
* http://maven.apache.org/ref/3.1.0/maven-model/maven.html
Artifacts
• An artifact is a file (jar, war, ear, etc), that gets deployed to a
Maven repository.
• Maven provides a large database of artifacts in maven
central repository http://search.maven.org/
• Artifact Repository Sonatype Nexus 2.3.x
Proxies maven central repository
Proxies other third party repositories (Apache, jBoss, etc)
Repository for Snapshot artifacts
Repository for Release artifacts
• Repository types
Maven has two types of repositories: local and remote.
Maven usually interacts with your local repository, but when a declared
dependency is not present in your local repository Maven searches all
the remote repositories it has access to in an attempt to find what’s
missing.
Dependencies
• Dependency Management
The key concept is that Maven dependencies are declarative. In the POM you
are not specifically telling Maven where the dependencies are physically, you
are simply telling Maven what a specific project expects.
• Where does that dependency come from ?
When a dependency is declared, Maven tries to satisfy that dependency by
looking in all of the remote repositories that are available, within the context of
your project, for artifacts that match the dependency request. If a matching
artifact is located, Maven transports it from that remote repository to your local
repository for general use.
• Transitive dependencies
Transitive dependencies are a feature introduced in Maven 2.0. This allows you to
avoid needing to discover and specify the libraries that your own dependencies
require, and including them automatically.
Dependencies - Scope
In a real-world enterprise application, you may not need to include all the
dependencies in the deployed application. Some JARs are needed only for unit
testing, while others will be provided at runtime by the application server. Using a
technique called dependency scoping, Maven lets you use certain JARs only
when you really need them and excludes them from the classpath when you
don't.
Maven provides four dependency scopes:
• compile: A compile-scope dependency is available in all phases. This is the default
value.
• provided: A provided dependency is used to compile the application, but will not be
deployed. You would use this scope when you expect the JDK or application server to
provide the JAR. The servlet APIs are a good example.
• runtime: Runtime-scope dependencies are not needed for compilation, only for
execution, such as JDBC (Java Database Connectivity) drivers. These dependencies will
be packaged in the final archive (e.g. will be packages in a War or Ear archive)
• test: Test-scope dependencies are needed only to compile and run tests (JUnit, for
example).
Lifecycle phases
Basic phases:
• validate - validate the project is correct and all necessary information is available
• compile - compile the source code of the project
• test - test the compiled source code using a suitable unit testing framework. These tests
should not require the code be packaged or deployed
• package - take the compiled code and package it in its distributable format, such as a
JAR.
• integration-test - process and deploy the package if necessary into an environment
where integration tests can be run
• verify - run any checks to verify the package is valid and meets quality criteria
• install - install the package into the local repository, for use as a dependency in other
projects locally
• deploy - done in an integration or release environment, copies the final package to the
remote repository for sharing with other developers and projects.
These build phases (plus the other build phases not
shown here) are executed sequentially to complete
the default lifecycle.
Plugins
Core maven plugins:
 Compiler plugin
 Surefire plugin
 EJB plugin
 War plugin
 EAR plugin
Other plugins:
 Release plugin
 War overlay plugin
 Resources plugin
Plugins are downloaded and installed automatically, if not present on your local system, in
much the same way that a dependency is handled.
${home.repository}.m2repositoryorgapachemavenplugins
API for creating your own maven plugins.
http://maven.apache.org/plugin-developers/
Plugins – compiler plugin
Used to compile the source files
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Plugins – surefire plugin
Used to run Tests.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
….
</configuration>
</plugin>
* Note that the Surefire plugin (which executes the test) looks for tests
contained in files with a particular naming convention. By default, the
following tests are included:
• **/*Test.java
• **/Test*.java
• **/*TestCase.java
* To execute one Test at a time, run mvn test -Dtest=MyUnitlTest
Plugins – ejb plugin
Used to create EJB artifacts
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${maven.ejb.plugin.version}</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
http://maven.apache.org/plugins/maven-ejb-plugin/
Plugins – war plugin
Used to create WAR artifacts
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>webApplication</warSourceDirectory>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
http://maven.apache.org/plugins/maven-war-plugin/
Plugins – ear plugin
Used to create EAR artifacts
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<displayName>myEAR</displayName>
<applicationName>myEAR</applicationName>
<!-- dynamically generate application.xml -->
<generateApplicationXml>true</generateApplicationXml>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<version>6</version>
<modules>
<ejbModule>
<groupId>com.manolis</groupId>
<artifactId>main</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>main.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>com.manolis</groupId>
<artifactId>web</artifactId>
<bundleFileName>web.war</bundleFileName>
<bundleDir>/</bundleDir>
<contextRoot>/web</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
Profiles
• Profiles are Maven's way of letting you create environmental variations in the build life
cycle to accommodate things like building on different platforms, building with different
JVMs, testing with different databases, or referencing the local file system. Typically you
try to encapsulate as much as possible in the POM to ensure that builds are portable, but
sometimes you simply have to take into consideration variation across systems and this is
why profiles were introduced in Maven.
• Profiles are specified using a subset of the elements available in the POM itself (plus one
extra section), and can be activated in several ways. Profiles modify the POM at build
time, and are meant to be used in complementary sets to give equivalent-but-different
parameters for a set of target environments (providing, for example, the path of the
application server root in the development, testing, and production environments).
• You can define profiles in one of the following three places:
• The Maven settings file (typically <your -home-directory>/.m2/settings.xml)
• A file in the the same directory as the POM, called profiles.xml
• The POM itself
IDE integration… (the problems
start here )
• All major IDEs have maven support
• Eclipse, IntelliJ, Netbeans
• BUT…
Potential problems :
• Auto publishing to application servers
• IDE warnings on maven projects
Useful maven commands
• mvn -version
• mvn clean This will remove the target directory
• mvn package
• mvn install
Installs the artifact (the JAR file) you've generated into your local repository. It can
then be used by other projects as a dependency. The directory <your-
homedirectory>/. m2/repository is the default location of the repository.
• mvn test
• mvn test -Dtest=MyUnitlTest
• mvn dependency:tree
Beyond Maven - The big picture
Continuous Integration Server (e.g. Jenkins)
Maven
Modules and dependencies
Build Testing
Code
Analysis
Deployment -
Integration
Artifact Repository (e.g. Nexus)
Caching Proxy for libraries Releases
References
o http://maven.apache.org/
o http://maven.apache.org/ref/3.1.0/maven-model/maven.html
o http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
o http://maven.apache.org/guides/introduction/introduction-to-the-
lifecycle.html#Lifecycle_Reference
o http://maven.apache.org/plugins/maven-ejb-plugin/
o http://maven.apache.org/maven-release/maven-release-plugin/
o http://maven.apache.org/plugin-developers/
o http://search.maven.org/
o http://eclipse.org/m2e/
o http://jenkins-ci.org/
o http://www.sonatype.org/nexus/
o http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html
o http://www.ibm.com/developerworks/java/tutorials/j-mavenv2/section2.html
o “Better Builds with Maven” Vincent Massol & Jason van Zyl
Introduction to maven

More Related Content

What's hot

Maven ppt
Maven pptMaven ppt
Maven ppt
natashasweety7
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
Mika Koivisto
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Introboyw165
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
Robert Burrell Donkin
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
Dragos Balan
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
Tomer Gabel
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
James Cellini
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
David Noble
 
Maven basics
Maven basicsMaven basics
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeHolasz Kati
 
Maven
MavenMaven
Maven
feng lee
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang
 

What's hot (20)

Maven ppt
Maven pptMaven ppt
Maven ppt
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven
MavenMaven
Maven
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Maven
MavenMaven
Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 

Similar to Introduction to maven

Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh656748
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
Mithilesh Singh
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
Scheidt & Bachmann
 
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
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Maven
MavenMaven
Maven
Emprovise
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma
 
What is maven
What is mavenWhat is maven
What is maven
sureshraj43
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions
 
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
Joelith
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
SISTechnologies
 
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
Dmitry Bakaleinik
 
Maven
MavenMaven

Similar to Introduction to maven (20)

Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
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 in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
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 with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven
MavenMaven
Maven
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
What is maven
What is mavenWhat is maven
What is maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
Continuous Integration Fundamentals: Maven - OFM Canberra July 2014
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
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
 
Maven
MavenMaven
Maven
 
Mavenppt
MavenpptMavenppt
Mavenppt
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

Introduction to maven

  • 2. “Maven” what ? Official site says that: “Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.”
  • 3. …What ??????? Maven is : o A top-level open source Apache Software Foundation project o A popular build tool o A dependency management tool o A release management tool The picture describes the Maven operation and interaction model.
  • 4. Why Maven? • Dependency management • Modularity • Code reusability • Abstraction of Build process (no dependency on IDEs) • Automated processes (deployments, unit & integration tests, etc)
  • 5. Project Structure src/main/java: Your Java source code goes here src/main/resources: Other resources your application needs. All directories or files placed within the src/main/resources directory are packaged in your JAR with the exact same structure, starting at the base of the JAR src/main/filters: Resource filters, in the form of properties files, which may be used to define variables only known at runtime src/main/config: Configuration files. The directory [src/main/config] doesn't show up on the classpath so the application or test classes can't read anything in it. src/main/webapp: The Web application directory for a WAR project src/test/java: Unit tests (will not be deployed) src/test/resources: Resources to be used for unit tests, but will not be deployed src/test/filters: Resources filters to be used for unit tests, but will not be deployed src/site: Files used to generate the Maven project Website
  • 6. Key Concepts  POM  Artifacts  Dependencies  Lifecycle phases  Plugins  Profiles
  • 7. POM • POM o Stands for Project Object Model o Is Maven’s description of a single project o Is an XML document o Contains a detailed description of your project, including information about versioning and configuration management, dependencies, application and testing resources, team members and structure, and much more
  • 8. POM basic elements • project – the top level element • modelVersion - the version of the object model • groupId – indicates the unique identifier of the organization or group that created the project • artifactId – indicates the unique name of the primary artifact being generated by this project • packaging – indicates the package type to be used by this artifact (jar, war, ear, etc). Default value is jar • version – indicates the version of the artifact generated by the project • name – indicates the display name used for the project • url – indicates where the project’s site can be found • description – provides a basic description for the project * http://maven.apache.org/ref/3.1.0/maven-model/maven.html
  • 9. Artifacts • An artifact is a file (jar, war, ear, etc), that gets deployed to a Maven repository. • Maven provides a large database of artifacts in maven central repository http://search.maven.org/ • Artifact Repository Sonatype Nexus 2.3.x Proxies maven central repository Proxies other third party repositories (Apache, jBoss, etc) Repository for Snapshot artifacts Repository for Release artifacts • Repository types Maven has two types of repositories: local and remote. Maven usually interacts with your local repository, but when a declared dependency is not present in your local repository Maven searches all the remote repositories it has access to in an attempt to find what’s missing.
  • 10. Dependencies • Dependency Management The key concept is that Maven dependencies are declarative. In the POM you are not specifically telling Maven where the dependencies are physically, you are simply telling Maven what a specific project expects. • Where does that dependency come from ? When a dependency is declared, Maven tries to satisfy that dependency by looking in all of the remote repositories that are available, within the context of your project, for artifacts that match the dependency request. If a matching artifact is located, Maven transports it from that remote repository to your local repository for general use. • Transitive dependencies Transitive dependencies are a feature introduced in Maven 2.0. This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.
  • 11. Dependencies - Scope In a real-world enterprise application, you may not need to include all the dependencies in the deployed application. Some JARs are needed only for unit testing, while others will be provided at runtime by the application server. Using a technique called dependency scoping, Maven lets you use certain JARs only when you really need them and excludes them from the classpath when you don't. Maven provides four dependency scopes: • compile: A compile-scope dependency is available in all phases. This is the default value. • provided: A provided dependency is used to compile the application, but will not be deployed. You would use this scope when you expect the JDK or application server to provide the JAR. The servlet APIs are a good example. • runtime: Runtime-scope dependencies are not needed for compilation, only for execution, such as JDBC (Java Database Connectivity) drivers. These dependencies will be packaged in the final archive (e.g. will be packages in a War or Ear archive) • test: Test-scope dependencies are needed only to compile and run tests (JUnit, for example).
  • 12. Lifecycle phases Basic phases: • validate - validate the project is correct and all necessary information is available • compile - compile the source code of the project • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed • package - take the compiled code and package it in its distributable format, such as a JAR. • integration-test - process and deploy the package if necessary into an environment where integration tests can be run • verify - run any checks to verify the package is valid and meets quality criteria • install - install the package into the local repository, for use as a dependency in other projects locally • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. These build phases (plus the other build phases not shown here) are executed sequentially to complete the default lifecycle.
  • 13. Plugins Core maven plugins:  Compiler plugin  Surefire plugin  EJB plugin  War plugin  EAR plugin Other plugins:  Release plugin  War overlay plugin  Resources plugin Plugins are downloaded and installed automatically, if not present on your local system, in much the same way that a dependency is handled. ${home.repository}.m2repositoryorgapachemavenplugins API for creating your own maven plugins. http://maven.apache.org/plugin-developers/
  • 14. Plugins – compiler plugin Used to compile the source files <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>
  • 15. Plugins – surefire plugin Used to run Tests. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.2</version> <configuration> …. </configuration> </plugin> * Note that the Surefire plugin (which executes the test) looks for tests contained in files with a particular naming convention. By default, the following tests are included: • **/*Test.java • **/Test*.java • **/*TestCase.java * To execute one Test at a time, run mvn test -Dtest=MyUnitlTest
  • 16. Plugins – ejb plugin Used to create EJB artifacts <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ejb-plugin</artifactId> <version>${maven.ejb.plugin.version}</version> <configuration> <ejbVersion>3.1</ejbVersion> </configuration> </plugin> http://maven.apache.org/plugins/maven-ejb-plugin/
  • 17. Plugins – war plugin Used to create WAR artifacts <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <warSourceDirectory>webApplication</warSourceDirectory> <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> </configuration> </plugin> http://maven.apache.org/plugins/maven-war-plugin/
  • 18. Plugins – ear plugin Used to create EAR artifacts <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <configuration> <displayName>myEAR</displayName> <applicationName>myEAR</applicationName> <!-- dynamically generate application.xml --> <generateApplicationXml>true</generateApplicationXml> <defaultLibBundleDir>lib</defaultLibBundleDir> <skinnyWars>true</skinnyWars> <version>6</version> <modules> <ejbModule> <groupId>com.manolis</groupId> <artifactId>main</artifactId> <bundleDir>/</bundleDir> <bundleFileName>main.jar</bundleFileName> </ejbModule> <webModule> <groupId>com.manolis</groupId> <artifactId>web</artifactId> <bundleFileName>web.war</bundleFileName> <bundleDir>/</bundleDir> <contextRoot>/web</contextRoot> </webModule> </modules> </configuration> </plugin>
  • 19. Profiles • Profiles are Maven's way of letting you create environmental variations in the build life cycle to accommodate things like building on different platforms, building with different JVMs, testing with different databases, or referencing the local file system. Typically you try to encapsulate as much as possible in the POM to ensure that builds are portable, but sometimes you simply have to take into consideration variation across systems and this is why profiles were introduced in Maven. • Profiles are specified using a subset of the elements available in the POM itself (plus one extra section), and can be activated in several ways. Profiles modify the POM at build time, and are meant to be used in complementary sets to give equivalent-but-different parameters for a set of target environments (providing, for example, the path of the application server root in the development, testing, and production environments). • You can define profiles in one of the following three places: • The Maven settings file (typically <your -home-directory>/.m2/settings.xml) • A file in the the same directory as the POM, called profiles.xml • The POM itself
  • 20. IDE integration… (the problems start here ) • All major IDEs have maven support • Eclipse, IntelliJ, Netbeans • BUT… Potential problems : • Auto publishing to application servers • IDE warnings on maven projects
  • 21. Useful maven commands • mvn -version • mvn clean This will remove the target directory • mvn package • mvn install Installs the artifact (the JAR file) you've generated into your local repository. It can then be used by other projects as a dependency. The directory <your- homedirectory>/. m2/repository is the default location of the repository. • mvn test • mvn test -Dtest=MyUnitlTest • mvn dependency:tree
  • 22. Beyond Maven - The big picture Continuous Integration Server (e.g. Jenkins) Maven Modules and dependencies Build Testing Code Analysis Deployment - Integration Artifact Repository (e.g. Nexus) Caching Proxy for libraries Releases
  • 23. References o http://maven.apache.org/ o http://maven.apache.org/ref/3.1.0/maven-model/maven.html o http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html o http://maven.apache.org/guides/introduction/introduction-to-the- lifecycle.html#Lifecycle_Reference o http://maven.apache.org/plugins/maven-ejb-plugin/ o http://maven.apache.org/maven-release/maven-release-plugin/ o http://maven.apache.org/plugin-developers/ o http://search.maven.org/ o http://eclipse.org/m2e/ o http://jenkins-ci.org/ o http://www.sonatype.org/nexus/ o http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html o http://www.ibm.com/developerworks/java/tutorials/j-mavenv2/section2.html o “Better Builds with Maven” Vincent Massol & Jason van Zyl