SlideShare una empresa de Scribd logo
1 de 42
Learning Maven by
example
Hsi-Kai Wang
Outline
• Introduction to Maven
• Example 1 - simple case
– build jar with command
– build jar with maven
• Example 2 - complex case
– optimize POM
• Maven Repository
• Maven Project on Jenkins
Build Jar Flow
submit sync
send email
deploy
dependency
Introduction to Maven
• What is maven
– A more formal definition of Apache Maven: 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.
• Convention over Configuration
– Maven concept is "Convention over Configuration". Maven
provides default values for the project's configuration.
Systems, libraries, and frameworks should assume
reasonable defaults. Without requiring unnecessary
configuration, systems should "just work"
Ref: apche Maven
Installation
• # install maven
centos:~ # wget
http://ftp.tc.edu.tw/pub/Apache/maven/maven-
3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
centos:~ # tar zxf apache-maven-3.3.9-bin.tar.gz -C
/opt
centos:~ # ln -s /opt/apache-maven-3.3.9 /opt/apache-
maven
• # setup environment variable
centos:~ # export MAVEN_HOME=/opt/apache-maven
centos:~ # export PATH=$PATH:$MAVEN_HOME/bin
centos:~ # echo $JAVA_HOME
centos:~ # mvn -v
• # other maven options
centos:~ # export MAVEN_OPTS="-Xms512m"
Example 1 - code & config
mypackage/Hello.java
log4j.properties
mypackage/HelloTest.java
Example 1 – build, run & test
• # compile
centos:~ # javac -cp log4j-1.2.12.jar
mypackage/Hello.java
centos:~ # javac -cp ~/junit-4.10.jar:mypackage.jar
mypackage/HelloTest.java
• # package (create jar)
centos:~ # jar cf mypackage.jar mypackage
• # run
centos:~ # java -cp log4j-1.2.12.jar:mypackage.jar -
Dlog4j.configuration=file:///root/log4j.properties
centos:~ # java -cp ~/junit-4.10.jar:mypackage.jar
org.junit.runner.JUnitCore mypackage/HelloTest
Example 1 - maven folder
structureproject folder
test case folder
application folder
Example 1 - pom.xml
jar cf mypackage.jar mypackage
javac -cp log4j-1.2.12.jar mypackage/Hello.java
java -cp log4j-1.2.12.jar mypackage
Example 1 - maven command
• # help
centos:~/project # mvn help:describe -Dplugin=clean [-
Dfull]
• # compile
centos:~/project # mvn clean compile
• # run test case
centos:~/project # mvn clean test [-
Dmaven.test.failure.ignore=true]
• # package
centos:~/project # mvn clean package
• # install module
centos:~/project # mvn clean install [-DskipTests]
• # run
centos:~/project # mvn exec:java [-
Dexec.mainClass=mypackage.Hello]
Example 1 - mvn compile &
package
Maven Core Concept
• Coordinates
• Plugins and Goals
• Lifecycle
• Repositories
• Dependency Management
• Site Generation and Reporting
Coordinates
coordinates
description
Plugin and Goal
• Maven is - at its heart - a plugin execution framework; all work is
done by plugins(Plugin is a collection of one or more goals).
Looking for a specific goal to execute? This page lists the core
plugins and others. There are the build and the reporting plugins:
– Build plugins will be executed during the build and they should
be configured in the <build/> element from the POM.
– Reporting plugins will be executed during the site generation
and they should be configured in the <reporting/> element from
the POM/
Lifecycle
• A build lifecycle is an organized
sequence of phases that exist to
give order to a set of goals.
Those goals are chosen and
bound by the packaging type of
the project being acted upon.
There are three standard
lifecycles in Maven: clean, default
(sometimes called build) and site.
Command Syntax
• # syntax 1
centos:~/project # mvn <coordinate>:<goal>
centos:~/project # mvn
org.apache.maven.plugin:maven-help-
plugin:2.1:describe
• # syntax 2
centos:~/project # mvn <plugin>:<goal>
centos:~/project # mvn help:describe
• # syntax 3
centos:~/project # mvn <phase>
centos:~/project # mvn compile
<groupId>:<artifactId>:<version>:<goal>
Default/Build lifecycle phase
• Default
– Handle project building and deployment
validate compile test
packagedeploy install
Lifecycle – clean and site
phases
• Clean
– Cleaning target folder and generated file
• Site
– Generate documentation
pre-clean clean post-clean
pre-site site post-site site-deploy
Repositories
/<groupId>/<artifactId>/<version>/<artifactId>-<version>.<packaging>
Dependency Management
• transitive dependency
Site Generation and Reporting
POM component
• properties
• dependencies
• plugins
• parent
• modules
• dependencyManagement
• pluginManagement
POM component - properties
• centos:~/project # mvn clean package
• centos:~/project # mvn clean package -
Dmypackage.version=1.2-SNAPSHOT
POM component -
dependencies
POM component - plugins
Example 2
ref: Maven by Example
POM component - modules
POM component - parent
Optimize POM
POM component -
dependencyManagement
Maven repository
• Open Source:
– Apache Archiva
– JFrog Artifactory Open Source
– Sonatype Nexus OSS
• Commercial:
– JFrog Artifactory Pro
– Sonatype Nexus Pro
Ref: Best Practice - Using a Repository Manager
Sonatype Maven repository -
installation• # Setup firewall
centos:~ # firewall-cmd --zone=public --add-port=8081/tcp –
permanent
centos:~ # firewall-cmd --zone=public --add-service=http –
permanent
centos:~ # firewall-cmd –reload
• # Download & uncompress package
http://www.sonatype.org/nexus/go/
• # Run
centos:~ # /opt/nexus/bin/nexus start
centos:~ # /opt/nexus/bin/nexus stop
centos:~ # /opt/nexus/bin/nexus console
• # Browser
http://localhost:8081/nexus
Administrator (admin/admin123)
Depolyment (depolyment/depolyment123)
Hosted Repository - Nexus
Hosted Repository
Proxy Repository
Virtual Repository
Repository Group
Snapshot
Release
Hosted Repository - mvn deploy
~/.m2/settings.xml
project/pom.xml
Proxy Repository - Nexus
Maven Repository – method 1
~/.m2/settings.xml
Maven Repository – method 2
~/.m2/settings.xml
Repository Group- Nexus
Maven Project on Jenkins (1)
Maven Project on Jenkins (2)
Maven Project on Jenkins (3)
reference
• Apache Maven Project
• Maven by Example
• Maven Tutorial - TutorialsPoint

Más contenido relacionado

La actualidad más candente

Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 OverviewMike Ensor
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and AntDavid Noble
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with MavenSid Anand
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2andyhot
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenGeert Pante
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Introboyw165
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for DummiesTomer Gabel
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
 

La actualidad más candente (20)

Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Development Tools - Maven
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven
MavenMaven
Maven
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in Maven
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven tutorial for beginners
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 

Destacado

Are you remotely agile? SGFLA 2016
Are you remotely agile? SGFLA 2016Are you remotely agile? SGFLA 2016
Are you remotely agile? SGFLA 2016Mark Kilby
 
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)Tamas Cservenak
 
Using Jenkins XML API
Using Jenkins XML APIUsing Jenkins XML API
Using Jenkins XML APIAnton Weiss
 
Continuous Delivery with Jenkins Workflow
Continuous Delivery with Jenkins WorkflowContinuous Delivery with Jenkins Workflow
Continuous Delivery with Jenkins WorkflowUdaypal Aarkoti
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)CloudBees
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Docker, Inc.
 

Destacado (7)

Are you remotely agile? SGFLA 2016
Are you remotely agile? SGFLA 2016Are you remotely agile? SGFLA 2016
Are you remotely agile? SGFLA 2016
 
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)
Smart Repository Management (openBlend 2011, Ljubljana, Slovenia)
 
Using Jenkins XML API
Using Jenkins XML APIUsing Jenkins XML API
Using Jenkins XML API
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Continuous Delivery with Jenkins Workflow
Continuous Delivery with Jenkins WorkflowContinuous Delivery with Jenkins Workflow
Continuous Delivery with Jenkins Workflow
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
 

Similar a Learning Maven by Example

Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svnAnkur Goyal
 
Open Source tools overview
Open Source tools overviewOpen Source tools overview
Open Source tools overviewLuciano Resende
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsSISTechnologies
 
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
 
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
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to MavenEric Wyles
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace MavenGuy Marom
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
Java build tools
Java build toolsJava build tools
Java build toolsSujit Kumar
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomavenManav Prasad
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in MuleShahid Shaik
 
maven
mavenmaven
mavenakd11
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldDmitry Bakaleinik
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
 

Similar a Learning Maven by Example (20)

Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
 
Maven
MavenMaven
Maven
 
Open Source tools overview
Open Source tools overviewOpen Source tools overview
Open Source tools overview
 
4 maven junit
4 maven junit4 maven junit
4 maven junit
 
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
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
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
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Java build tools
Java build toolsJava build tools
Java build tools
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in Mule
 
maven
mavenmaven
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
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Maven basic concept
Maven basic conceptMaven basic concept
Maven basic concept
 

Último

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Último (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Learning Maven by Example

  • 2. Outline • Introduction to Maven • Example 1 - simple case – build jar with command – build jar with maven • Example 2 - complex case – optimize POM • Maven Repository • Maven Project on Jenkins
  • 3. Build Jar Flow submit sync send email deploy dependency
  • 4. Introduction to Maven • What is maven – A more formal definition of Apache Maven: 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. • Convention over Configuration – Maven concept is "Convention over Configuration". Maven provides default values for the project's configuration. Systems, libraries, and frameworks should assume reasonable defaults. Without requiring unnecessary configuration, systems should "just work" Ref: apche Maven
  • 5. Installation • # install maven centos:~ # wget http://ftp.tc.edu.tw/pub/Apache/maven/maven- 3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz centos:~ # tar zxf apache-maven-3.3.9-bin.tar.gz -C /opt centos:~ # ln -s /opt/apache-maven-3.3.9 /opt/apache- maven • # setup environment variable centos:~ # export MAVEN_HOME=/opt/apache-maven centos:~ # export PATH=$PATH:$MAVEN_HOME/bin centos:~ # echo $JAVA_HOME centos:~ # mvn -v • # other maven options centos:~ # export MAVEN_OPTS="-Xms512m"
  • 6. Example 1 - code & config mypackage/Hello.java log4j.properties mypackage/HelloTest.java
  • 7. Example 1 – build, run & test • # compile centos:~ # javac -cp log4j-1.2.12.jar mypackage/Hello.java centos:~ # javac -cp ~/junit-4.10.jar:mypackage.jar mypackage/HelloTest.java • # package (create jar) centos:~ # jar cf mypackage.jar mypackage • # run centos:~ # java -cp log4j-1.2.12.jar:mypackage.jar - Dlog4j.configuration=file:///root/log4j.properties centos:~ # java -cp ~/junit-4.10.jar:mypackage.jar org.junit.runner.JUnitCore mypackage/HelloTest
  • 8. Example 1 - maven folder structureproject folder test case folder application folder
  • 9. Example 1 - pom.xml jar cf mypackage.jar mypackage javac -cp log4j-1.2.12.jar mypackage/Hello.java java -cp log4j-1.2.12.jar mypackage
  • 10. Example 1 - maven command • # help centos:~/project # mvn help:describe -Dplugin=clean [- Dfull] • # compile centos:~/project # mvn clean compile • # run test case centos:~/project # mvn clean test [- Dmaven.test.failure.ignore=true] • # package centos:~/project # mvn clean package • # install module centos:~/project # mvn clean install [-DskipTests] • # run centos:~/project # mvn exec:java [- Dexec.mainClass=mypackage.Hello]
  • 11. Example 1 - mvn compile & package
  • 12. Maven Core Concept • Coordinates • Plugins and Goals • Lifecycle • Repositories • Dependency Management • Site Generation and Reporting
  • 14. Plugin and Goal • Maven is - at its heart - a plugin execution framework; all work is done by plugins(Plugin is a collection of one or more goals). Looking for a specific goal to execute? This page lists the core plugins and others. There are the build and the reporting plugins: – Build plugins will be executed during the build and they should be configured in the <build/> element from the POM. – Reporting plugins will be executed during the site generation and they should be configured in the <reporting/> element from the POM/
  • 15. Lifecycle • A build lifecycle is an organized sequence of phases that exist to give order to a set of goals. Those goals are chosen and bound by the packaging type of the project being acted upon. There are three standard lifecycles in Maven: clean, default (sometimes called build) and site.
  • 16. Command Syntax • # syntax 1 centos:~/project # mvn <coordinate>:<goal> centos:~/project # mvn org.apache.maven.plugin:maven-help- plugin:2.1:describe • # syntax 2 centos:~/project # mvn <plugin>:<goal> centos:~/project # mvn help:describe • # syntax 3 centos:~/project # mvn <phase> centos:~/project # mvn compile <groupId>:<artifactId>:<version>:<goal>
  • 17. Default/Build lifecycle phase • Default – Handle project building and deployment validate compile test packagedeploy install
  • 18. Lifecycle – clean and site phases • Clean – Cleaning target folder and generated file • Site – Generate documentation pre-clean clean post-clean pre-site site post-site site-deploy
  • 21. Site Generation and Reporting
  • 22. POM component • properties • dependencies • plugins • parent • modules • dependencyManagement • pluginManagement
  • 23. POM component - properties • centos:~/project # mvn clean package • centos:~/project # mvn clean package - Dmypackage.version=1.2-SNAPSHOT
  • 25. POM component - plugins
  • 26. Example 2 ref: Maven by Example
  • 27. POM component - modules
  • 28. POM component - parent
  • 31. Maven repository • Open Source: – Apache Archiva – JFrog Artifactory Open Source – Sonatype Nexus OSS • Commercial: – JFrog Artifactory Pro – Sonatype Nexus Pro Ref: Best Practice - Using a Repository Manager
  • 32. Sonatype Maven repository - installation• # Setup firewall centos:~ # firewall-cmd --zone=public --add-port=8081/tcp – permanent centos:~ # firewall-cmd --zone=public --add-service=http – permanent centos:~ # firewall-cmd –reload • # Download & uncompress package http://www.sonatype.org/nexus/go/ • # Run centos:~ # /opt/nexus/bin/nexus start centos:~ # /opt/nexus/bin/nexus stop centos:~ # /opt/nexus/bin/nexus console • # Browser http://localhost:8081/nexus Administrator (admin/admin123) Depolyment (depolyment/depolyment123)
  • 33. Hosted Repository - Nexus Hosted Repository Proxy Repository Virtual Repository Repository Group Snapshot Release
  • 34. Hosted Repository - mvn deploy ~/.m2/settings.xml project/pom.xml
  • 36. Maven Repository – method 1 ~/.m2/settings.xml
  • 37. Maven Repository – method 2 ~/.m2/settings.xml
  • 39. Maven Project on Jenkins (1)
  • 40. Maven Project on Jenkins (2)
  • 41. Maven Project on Jenkins (3)
  • 42. reference • Apache Maven Project • Maven by Example • Maven Tutorial - TutorialsPoint

Notas del editor

  1. 在 coordinate 可以省略成 下面 plugin 模式
  2. Download and Upload
  3. https://github.com/sonatype/maven-example-en