SlideShare una empresa de Scribd logo
1 de 31
Apache Maven
Volodymyr Ostapiv
2014
Agenda
▪ What is Maven
▪ Getting and installing
▪ Basics: POM, GAV, Archetype
▪ pom.xml contents
▪ Some useful plugins
What is Maven
▪Maven is a build automation tool used
primarily for Java projects.
▪ Maven addresses two aspects of building
software:
1. it describes how software is built
2. it describes its dependencies
Maven LifeCycle
•Default lifecycle
–generate-sources/generate-resources
–compile
–test
–package
–integration-test (pre and post)
–install
–Deploy
•Separate “clean” lifecycle
History
– Maven 1 (2003)
– Maven 2 (2005)
▪ Not backwards Compatible
– Maven 3 (2010)
▪ Same as Maven 2 but more stable and with some
additional features
Get it!
Configure
%MAVEN_HOME%confsettings.xml
/usr/local/maven/conf/settings.xml
UserProfile.m2
~/.m2/
Create simple project
mvn archetype:generate
-DgroupId=[myGroup]
-DartifactId=[myArtifact]
-DarchetypeArtifactId=maven-
archetype-archetype
OR
mvn archetype:generate
Arche-who? O_o
An archetype is defined as an original pattern or model
from which all other things of the same kind are made.
Archetype is a Maven project templating toolkit.
Maven + IDE
mvn idea:idea mvn eclipse:eclipse
Generate project files for the most popular IDEs
Path Conventions
Maven Project Object Model (POM)
▪ Describes a project
– Name and Version
– Artifact Type
– Source Code Locations
– Dependencies
– Plugins
– Profiles (Alternate build config.)
▪ Uses XML by default
Project Name (GAV)
▪ Maven uniquely identifies a project using:
– groupID: project grouping identifier (no spaces
or colons)
▪ Usually loosely based on Java package
– artfiactId: name of project (no spaces or
colons)
– version: Version of project
▪ Format {Major}.{Minor}.{Maintanence}
▪ Add ‘-SNAPSHOT ‘ to identify in development
Project Name (GAV)
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.lds.training</groupId>
<artifactId>maven-training</artifactId>
<version>1.0</version>
<name>Windows 8</name>
<description>The best OS ever!</description>
<packaging>jar</packaging>
<properties>
<java.version>1.6</java.version>
<properties>
</project>
Dependencies
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
<scope>compile</scope>
</dependency>
<dependencies>
Dependency scope
• compile (default)
• provided (by JDK or a container at runtime)
• runtime (not required for compilation)
• test (used only during tests)
• system
• import (only available in Maven 2.0.9 or later)
Properties
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>3.1.2.RELEASE</spring.version>
<spring.batch.version>2.1.8.RELEASE</spring.batch.version>
</properties>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>${spring.batch.version}</version>
</dependency>
mvn install -Dmyproperty=my property from command line
Exclusions
<exclusions>
<exclusion>
<groupId>org.softserve.sse</groupId>
<artifactId>softserve-sse</artifactId>
</exclusion>
</exclusions>
Profiles
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
(mvn install -Pprofilename)
Profile activation
Operating System based:
<activation>
<os>
<family>unix</family>
</os>
</activation>
<activation>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
</activation>
JDK based:
<activation>
<jdk>1.4</jdk>
</activation>
<activation>
<jdk>[1.3,1.6)</jdk>
</activation>
Profile activation
System property based:
<activation>
<property>
<name>environment</name>
<value>test</value>
</property>
</activation>
File system state based:
<activation>
<file>
<missing>
target/maven/somefile
</missing>
</file>
</activation>
Plugins
Here real magic starts
maven-surefire-plugin
surefire:test
jetty-maven-plugin
mvn jetty:run
tomcat-maven-plugin
mvn tomcat:run
maven-antrun-plugin
mvn antrun:run
maven-compiler-plugin
mvn compiler:compile
mvn compiler:testCompile
maven-assembly-plugin
mvn assembly:single
maven-shade-plugin
mvn shade:shade
maven-dependency-plugin
mvn dependency:analyze
mvn dependency:tree
That’s all

Más contenido relacionado

La actualidad más candente

An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar
 

La actualidad más candente (20)

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
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
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
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Introduction to Apache Maven
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Maven
Maven Maven
Maven
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 

Similar a Apache Maven for SoftServe IT Academy

Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent Projects
Mert Çalışkan
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
boyw165
 

Similar a Apache Maven for SoftServe IT Academy (20)

Apache Maven for AT/QC
Apache Maven for AT/QCApache Maven for AT/QC
Apache Maven for AT/QC
 
Apache Maven basics
Apache Maven basicsApache Maven basics
Apache Maven basics
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
 
maven
mavenmaven
maven
 
P&MSP2012 - Maven
P&MSP2012 - MavenP&MSP2012 - Maven
P&MSP2012 - Maven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent Projects
 
Ordina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - MavenOrdina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - Maven
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Maven
MavenMaven
Maven
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Apache Maven at GenevaJUG by Arnaud Héritier
Apache Maven at GenevaJUG by Arnaud HéritierApache Maven at GenevaJUG by Arnaud Héritier
Apache Maven at GenevaJUG by Arnaud Héritier
 
Geneva Jug (30th March, 2010) - Maven
Geneva Jug (30th March, 2010) - MavenGeneva Jug (30th March, 2010) - Maven
Geneva Jug (30th March, 2010) - Maven
 
Intro to Maven.ppt
Intro to Maven.pptIntro to Maven.ppt
Intro to Maven.ppt
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace Maven
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Apache Maven for SoftServe IT Academy

Notas del editor

  1. http://maven.apache.org/
  2. Build automation is the act of scripting or automating a wide variety of tasks that software developers do in their day-to-day activities including things like:compiling computer source code into binary codepackaging binary coderunning testsdeployment to production systemscreating documentation and/or release notes
  3. mvn installInvokes generate* and compile, test, package, integration-test, installmvn clean Invokes just cleanmvn clean compileClean old builds and execute generate*, compilemvn compile installInvokes generate*, compile, test, integration-test, package, installmvn test cleanInvokes generate*, compile, test then cleans
  4. 1. Install JDK, set JAVA_HOME2. Download and extract Apache Maven (http://maven.apache.org/)3. Add MAVEN_HOME system variable4. Add MAVEN_HOME to PATH5.“mvn –version“.
  5. &lt;project&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.softserve.demo&lt;/groupId&gt; &lt;artifactId&gt;simple-web-project&lt;/artifactId&gt; &lt;packaging&gt;war&lt;/packaging&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;3.8.1&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;finalName&gt;simple-web-project&lt;/finalName&gt; &lt;/build&gt; &lt;/project&gt;
  6. mvnarchetype:generate-DgroupId={com.softserve.demo}-DartifactId={simple-web-project}-DarchetypeArtifactId=maven-archetype-webapp-DinteractiveMode=false
  7. Maven is opinionated about project structuretarget: Default work directorysrc: All project source files go in this directorysrc/main: All sources that go into primary artifactsrc/test: All sources contributing to testing projectsrc/main/java: All java source filessrc/main/webapp: All web source filessrc/main/resources: All non compiled source filessrc/test/java: All java test source filessrc/test/resources: All non compiled test source files
  8. &lt;dependency&gt; &lt;groupId&gt;net.lightbody.bmp&lt;/groupId&gt; &lt;artifactId&gt;browsermob-proxy&lt;/artifactId&gt; &lt;version&gt;2.0-beta-8&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt;&lt;exclusions&gt;&lt;exclusion&gt; &lt;groupId&gt;org.softserve.sse&lt;/groupId&gt; &lt;artifactId&gt;softserve-sse&lt;/artifactId&gt; &lt;/exclusion&gt; &lt;/exclusions&gt;&lt;/dependency&gt;
  9. &lt;profiles&gt;&lt;profile&gt;&lt;id&gt;default&lt;/id&gt;&lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;&lt;/activation&gt; &lt;build&gt; &lt;finalName&gt;${name}&lt;/finalName&gt; &lt;plugins&gt; &lt;plugin&gt;…&lt;/plugin&gt; &lt;plugins&gt; &lt;/build&gt;&lt;/profile&gt;&lt;/profiles&gt;
  10. &lt;activation&gt; &lt;os&gt; &lt;family&gt;windows&lt;/family&gt; &lt;/os&gt;&lt;/activation&gt;
  11. Use –DskipTests to skip test
  12. http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
  13. http://tomcat.apache.org/maven-plugin.html
  14. https://maven.apache.org/plugins/maven-antrun-plugin/
  15. &lt;plugin&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.1&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;compilerArgument&gt;-proc:none&lt;/compilerArgument&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;run-annotation-processors-only&lt;/id&gt; &lt;phase&gt;generate-sources&lt;/phase&gt; &lt;configuration&gt; &lt;compilerArgument&gt;-proc:only&lt;/compilerArgument&gt; &lt;!-- If your app has multiple packages, use this include filter to execute the processor only on the package containing your entities --&gt; &lt;!-- &lt;includes&gt; &lt;include&gt;**/model/*.java&lt;/include&gt; &lt;/includes&gt; --&gt; &lt;/configuration&gt; &lt;goals&gt; &lt;goal&gt;compile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt;&lt;/plugin&gt;
  16. For Spring apps use onejar-maven-plugin&lt;plugin&gt;&lt;groupId&gt;com.jolira&lt;/groupId&gt;&lt;artifactId&gt;onejar-maven-plugin&lt;/artifactId&gt;&lt;version&gt;1.4.4&lt;/version&gt;&lt;executions&gt;&lt;execution&gt;&lt;configuration&gt;&lt;mainClass&gt;com.package.core.Main&lt;/mainClass&gt;&lt;!-- Optional, default is false --&gt;&lt;attachToBuild&gt;true&lt;/attachToBuild&gt;&lt;!-- Optional, default is &quot;one jar&quot; --&gt;&lt;classifier&gt;onejar&lt;/classifier&gt;&lt;/configuration&gt;&lt;goals&gt;&lt;goal&gt;one-jar&lt;/goal&gt;&lt;/goals&gt;&lt;/execution&gt;&lt;/executions&gt;&lt;/plugin&gt;
  17. http://maven.apache.org/plugins/maven-shade-plugin/
  18. &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt; &lt;version&gt;2.4&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;analyze&lt;/id&gt; &lt;phase&gt;verify&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;analyze-only&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;failOnWarning&gt;true&lt;/failOnWarning&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt;&lt;/plugin&gt;