SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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.
 

En vedette (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...
 

Similaire à 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
 

Similaire à 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
 

Dernier

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Dernier (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

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

Notes de l'éditeur

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