SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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.
 

Viewers also liked (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 to 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 to 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
 

Recently uploaded

Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 

Recently uploaded (20)

Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 

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

Editor's Notes

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