SlideShare a Scribd company logo
1 of 37
Apache Maven 2. Part 1: Overview

                                        Getting started with Apache Maven 2


                                            Nikolay Khasanov, Anatoly Kondratyev
                                                                   October 2012


23 January 2013
             Exigen Services confidential                      Exigen Services confidential
The Goal




• Understand Maven principles
• Build project with Maven
• Compare to Apache Ant




      Exigen Services confidential   2
What is Maven?

                               GETTING STARTED



Exigen Services confidential                      3
Glossary


• Artifact
  • .jar, .ear, .war, .pom, etc.
  • GroupId, ArtifactId, Version
• Maven repository
  • Holds artifacts
• Dependency
• POM file (Project Object Model)


       Exigen Services confidential   4
What is Maven?




•   Build automation tool
•   Open Source: Apache License 2.0
•   Knowledge accumulator
•   Declarative logic instead of imperative



        Exigen Services confidential          5
Maven’s Objectives



•   Making the build process easy
•   Providing a uniform build system
•   Providing quality project information
•   Providing guidelines for best practices
    development



        Exigen Services confidential          6
Change your mind

                               CORE MAVEN 2



Exigen Services confidential                    7
Maven project
   pom.xml

                       Project
                                               Dependency
                       Object
                                                Manager
                       Model


                                Project lifecycle                      Repositories


                  plug-in            plug-in        plug-in




     source            generated         resources            binary
      code               code                                  files

      Exigen Services confidential                                                8
Project Object Model (pom.xml)


                                              project
•   Identification                     groupId
                                              home              Spring
                                                                 2.5.6

•   Hierarchy                          artifactId
                                       version
                                                        parentsources

                                       type                      Junit
•   Structure                                 my-app              4.5
                                                             classes
                                                               Repository
•   Dependencies                              my-app          another-app
                                                                Servlet
•   Build settings                                               API
                                                               etc.
                                                                  2.5




        Exigen Services confidential                                        9
Super POM




•   Package: jar
•   Default project structure
•   Default artifacts Repository
•   Default plugins



        Exigen Services confidential   10
Default folders structure




      Exigen Services confidential   11
Maven does your work




• Store only source code
• Maven knows how to build
• Dependencies are stored in shared
  repository




      Exigen Services confidential    12
Transitive dependencies


                                        my-app




         dependency.1                    dependency.2   dependency.3




dependency.1.1            dependency.1.2




         Exigen Services confidential                                  13
Dependency scope

    Result Compile                        Runtime     Test        Lookup
Scope      classpath                      classpath   classpath   repository
compile                    +                   +           +             +
provided                   +                   -           +             +
runtime                    -                   +           +             +
test                       -                   -           +             +
system                     +                   -           +             -
import                         Maven 2.0.9 or later, replaces POM with
                                   <dependencyManagement>




           Exigen Services confidential                                        14
Maven Repository
  Local repository                     External repositories

                        user local      internal         external




                                                     Central (default)

   Maven




    User workstation                 Local network      Internet


      Exigen Services confidential                                   16
Simple Maven project example

                                  MAVEN IN ACTION



Exigen Services confidential                             17
Installation

1. Requirements:
  •   JRE/JDK 1.4 or higher
2. Download
3. Unzip
4. Setup environment variables:
  •   M2_HOME
  •   M2
  •   PATH
5. Enjoy 
       Exigen Services confidential   18
Configuration




• Global
  • <M2_HOME>/conf/settings.xml
• User local
  • <USER_HOME>/.m2/settings.xml




      Exigen Services confidential   19
mvn



• mvn [goal(s)] [phase(s)] [options]
  • goal = plugin:goal
  • phase = phase-name
• Examples:
  • mvn compiler:compile
  • mvn install –X –DsomeProperty=10




      Exigen Services confidential     21
Build lifecycle


1.   validate                       check pom.xml
2.   compile                        compile the source
3.   test                           run unit tests
4.   package                        create jar/war/...
5.   integration-test               run integration tests
6.   verify                         verify the package
7.   install                        publish package to local repo
8.   deploy                         publish package to remote repo


         Exigen Services confidential                            22
Start-up new project

mvn archetype:create
  -DarchetypeGroupId=org.apache.maven.archetypes
  -DgroupId=com.exigenservices.training
  -DartifactId=myjsf


Result:
                                      • Default folder structure
                                      • pom.xml
                                      • First java class
                                      • First unit-test class

       Exigen Services confidential                            23
pom.xml: Minimal POM

<project>

 <modelVersion>4.0.0</modelVersion>

 <groupId>com.exigenservices.app</groupId>
 <artifactId>myjsf</artifactId>
 <version>SNAPSHOT</version>

</project>




      Exigen Services confidential           24
pom.xml: Dependencies

<project>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>



      Exigen Services confidential           25
pom.xml: Plug-ins configuration
<project>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>


         Exigen Services confidential                26
Build project



• mvn install
  1.   validate
  2.   compile
  3.   test
  4.   package
  5.   install



        Exigen Services confidential   27
Install and Deploy
                                                               deploy


               local                developer 1

                                                    internal



               local                developer 2
install

                                 …
                                                                        external


               local               developer N
                                                  Local network Internet

          Exigen Services confidential                                             28
When deploy is needed?




• Release
• Update snapshot
  • Available for other projects




      Exigen Services confidential   29
Add repository

<repositories>
  <repository>
    <id>Jboss.repository</id>
    <url>
      http://repository.jboss.org/maven2
    </url>
  </repository>
</repositories>




      Exigen Services confidential         30
Develop with pleasure!

                               IDE INTEGRATION



Exigen Services confidential                         31
IDE list




• InteliJ IDEA from 7.0
• Eclipse (plug-in: “m2eclipse”)
• NetBeans 6.5




       Exigen Services confidential   32
IDE features




• POM editor
• Dependency synchronization
• Lifecycle build runners




      Exigen Services confidential   33
Let’s summarize

                               CONCLUSION



Exigen Services confidential                 34
Advantages (vs. Ant)



•   Know Maven – can build project
•   Dependency management
•   Less CM activities
•   Force to standardization
•   Readable pom.xml
•   High reusability


        Exigen Services confidential   35
Disadvantages (vs. Ant)



•   Understanding
•   Artifacts search
•   Plug-ins documentation
•   “Exotic things” - maven-ant-plugin
•   Difficult to move from Ant



        Exigen Services confidential     36
Maven repositories

• Central
   http://repo1.maven.org/maven2/
• Central repository Explorer
   http://mvnrepository.com
• Collection of plugins for Maven 2
   http://mojo.codehaus.org
• JBoss
   http://repository.jboss.com/maven2/
• Sun
   http://download.java.net/maven/2/
• Atlassian
   http://repository.atlassian.com/maven2/

          Exigen Services confidential       37
References

• Maven site
   http://maven.apache.org
• Quick guide
   http://maven.apache.org/guides/MavenQuickReferenceCard.pdf
• Maven FAQ
   http://docs.codehaus.org/display/MAVENUSER/FAQs-1
• Better Builds with Maven. John Casey and others
   http://www.exist.com/better-build-maven
• Maven overview in Russian
   http://www.ibm.com/developerworks/ru/edu/j-mavenv2/index.html
• m2eclipse plug-in
   http://m2eclipse.codehaus.org

         Exigen Services confidential                              38
Now it’s your turn…

                                QUESTIONS



Exigen Services confidential                    39

More Related Content

What's hot

What's hot (20)

Apache Maven 3
Apache Maven 3Apache Maven 3
Apache Maven 3
 
Maven
MavenMaven
Maven
 
AWS App Runner를 활용한 컨테이너 서버리스 활용기
AWS App Runner를 활용한 컨테이너 서버리스 활용기AWS App Runner를 활용한 컨테이너 서버리스 활용기
AWS App Runner를 활용한 컨테이너 서버리스 활용기
 
Maven
MavenMaven
Maven
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Jenkins for java world
Jenkins for java worldJenkins for java world
Jenkins for java world
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
분산 트랜잭션 환경에서 데이터 일관성 유지 방안 업로드용
분산 트랜잭션 환경에서 데이터 일관성 유지 방안 업로드용분산 트랜잭션 환경에서 데이터 일관성 유지 방안 업로드용
분산 트랜잭션 환경에서 데이터 일관성 유지 방안 업로드용
 
The Path Towards Spring Boot Native Applications
The Path Towards Spring Boot Native ApplicationsThe Path Towards Spring Boot Native Applications
The Path Towards Spring Boot Native Applications
 
Maven
MavenMaven
Maven
 
Java Spring
Java SpringJava Spring
Java Spring
 
Maven
MavenMaven
Maven
 
Jenkins Overview
Jenkins OverviewJenkins Overview
Jenkins Overview
 
Jenkins
JenkinsJenkins
Jenkins
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Maven
MavenMaven
Maven
 

Viewers also liked

Viewers also liked (10)

Apache Maven basics
Apache Maven basicsApache Maven basics
Apache Maven basics
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Introduction to Apache Maven
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
основы Java переменные, циклы
основы Java   переменные, циклыосновы Java   переменные, циклы
основы Java переменные, циклы
 
Maven
Maven Maven
Maven
 
Конспект лекций по курсу "Шаблоны разработки ПО"
Конспект лекций по курсу "Шаблоны разработки ПО"Конспект лекций по курсу "Шаблоны разработки ПО"
Конспект лекций по курсу "Шаблоны разработки ПО"
 
Как найти первую работу и как с нее не вылететь
Как найти первую работу и как с нее не вылететьКак найти первую работу и как с нее не вылететь
Как найти первую работу и как с нее не вылететь
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 

Similar to Apache maven 2 overview

How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
Fazreil Amreen Abdul Jalil
 
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
Renato Primavera
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
Alan Parkinson
 

Similar to Apache maven 2 overview (20)

Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Apache Maven 2 Part 2
Apache Maven 2 Part 2Apache Maven 2 Part 2
Apache Maven 2 Part 2
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace Maven
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
 
Apache maven 2. advanced topics
Apache maven 2. advanced topicsApache maven 2. advanced topics
Apache maven 2. advanced topics
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Maven overview
Maven overviewMaven overview
Maven overview
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
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
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Maven
MavenMaven
Maven
 
4 maven junit
4 maven junit4 maven junit
4 maven junit
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
 
Maven2交流
Maven2交流Maven2交流
Maven2交流
 

More from Return on Intelligence

Profsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by PavelchukProfsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by Pavelchuk
Return on Intelligence
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
Return on Intelligence
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обучения
Return on Intelligence
 

More from Return on Intelligence (20)

Profsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by PavelchukProfsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by Pavelchuk
 
Agile Project Grows
Agile Project GrowsAgile Project Grows
Agile Project Grows
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
 
Time Management
Time ManagementTime Management
Time Management
 
Service design principles and patterns
Service design principles and patternsService design principles and patterns
Service design principles and patterns
 
Differences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileDifferences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and Agile
 
Windows Azure: Quick start
Windows Azure: Quick startWindows Azure: Quick start
Windows Azure: Quick start
 
Windows azurequickstart
Windows azurequickstartWindows azurequickstart
Windows azurequickstart
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обучения
 
Shared position in a project: testing and analysis
Shared position in a project: testing and analysisShared position in a project: testing and analysis
Shared position in a project: testing and analysis
 
Introduction to Business Etiquette
Introduction to Business EtiquetteIntroduction to Business Etiquette
Introduction to Business Etiquette
 
Agile Testing Process
Agile Testing ProcessAgile Testing Process
Agile Testing Process
 
Оценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеОценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработке
 
Meetings arranging
Meetings arrangingMeetings arranging
Meetings arranging
 
How to develop your creativity
How to develop your creativityHow to develop your creativity
How to develop your creativity
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
The art of project estimation
The art of project estimationThe art of project estimation
The art of project estimation
 
Successful interview for a young IT specialist
Successful interview for a young IT specialistSuccessful interview for a young IT specialist
Successful interview for a young IT specialist
 
Risk Management
Risk ManagementRisk Management
Risk Management
 
Resolving conflicts
Resolving conflictsResolving conflicts
Resolving conflicts
 

Apache maven 2 overview

  • 1. Apache Maven 2. Part 1: Overview Getting started with Apache Maven 2 Nikolay Khasanov, Anatoly Kondratyev October 2012 23 January 2013 Exigen Services confidential Exigen Services confidential
  • 2. The Goal • Understand Maven principles • Build project with Maven • Compare to Apache Ant Exigen Services confidential 2
  • 3. What is Maven? GETTING STARTED Exigen Services confidential 3
  • 4. Glossary • Artifact • .jar, .ear, .war, .pom, etc. • GroupId, ArtifactId, Version • Maven repository • Holds artifacts • Dependency • POM file (Project Object Model) Exigen Services confidential 4
  • 5. What is Maven? • Build automation tool • Open Source: Apache License 2.0 • Knowledge accumulator • Declarative logic instead of imperative Exigen Services confidential 5
  • 6. Maven’s Objectives • Making the build process easy • Providing a uniform build system • Providing quality project information • Providing guidelines for best practices development Exigen Services confidential 6
  • 7. Change your mind CORE MAVEN 2 Exigen Services confidential 7
  • 8. Maven project pom.xml Project Dependency Object Manager Model Project lifecycle Repositories plug-in plug-in plug-in source generated resources binary code code files Exigen Services confidential 8
  • 9. Project Object Model (pom.xml) project • Identification groupId home Spring 2.5.6 • Hierarchy artifactId version parentsources type Junit • Structure my-app 4.5 classes Repository • Dependencies my-app another-app Servlet • Build settings API etc. 2.5 Exigen Services confidential 9
  • 10. Super POM • Package: jar • Default project structure • Default artifacts Repository • Default plugins Exigen Services confidential 10
  • 11. Default folders structure Exigen Services confidential 11
  • 12. Maven does your work • Store only source code • Maven knows how to build • Dependencies are stored in shared repository Exigen Services confidential 12
  • 13. Transitive dependencies my-app dependency.1 dependency.2 dependency.3 dependency.1.1 dependency.1.2 Exigen Services confidential 13
  • 14. Dependency scope Result Compile Runtime Test Lookup Scope classpath classpath classpath repository compile + + + + provided + - + + runtime - + + + test - - + + system + - + - import Maven 2.0.9 or later, replaces POM with <dependencyManagement> Exigen Services confidential 14
  • 15. Maven Repository Local repository External repositories user local internal external Central (default) Maven User workstation Local network Internet Exigen Services confidential 16
  • 16. Simple Maven project example MAVEN IN ACTION Exigen Services confidential 17
  • 17. Installation 1. Requirements: • JRE/JDK 1.4 or higher 2. Download 3. Unzip 4. Setup environment variables: • M2_HOME • M2 • PATH 5. Enjoy  Exigen Services confidential 18
  • 18. Configuration • Global • <M2_HOME>/conf/settings.xml • User local • <USER_HOME>/.m2/settings.xml Exigen Services confidential 19
  • 19. mvn • mvn [goal(s)] [phase(s)] [options] • goal = plugin:goal • phase = phase-name • Examples: • mvn compiler:compile • mvn install –X –DsomeProperty=10 Exigen Services confidential 21
  • 20. Build lifecycle 1. validate check pom.xml 2. compile compile the source 3. test run unit tests 4. package create jar/war/... 5. integration-test run integration tests 6. verify verify the package 7. install publish package to local repo 8. deploy publish package to remote repo Exigen Services confidential 22
  • 21. Start-up new project mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.exigenservices.training -DartifactId=myjsf Result: • Default folder structure • pom.xml • First java class • First unit-test class Exigen Services confidential 23
  • 22. pom.xml: Minimal POM <project> <modelVersion>4.0.0</modelVersion> <groupId>com.exigenservices.app</groupId> <artifactId>myjsf</artifactId> <version>SNAPSHOT</version> </project> Exigen Services confidential 24
  • 23. pom.xml: Dependencies <project> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.6</version> <scope>test</scope> </dependency> </dependencies> </project> Exigen Services confidential 25
  • 24. pom.xml: Plug-ins configuration <project> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project> Exigen Services confidential 26
  • 25. Build project • mvn install 1. validate 2. compile 3. test 4. package 5. install Exigen Services confidential 27
  • 26. Install and Deploy deploy local developer 1 internal local developer 2 install … external local developer N Local network Internet Exigen Services confidential 28
  • 27. When deploy is needed? • Release • Update snapshot • Available for other projects Exigen Services confidential 29
  • 28. Add repository <repositories> <repository> <id>Jboss.repository</id> <url> http://repository.jboss.org/maven2 </url> </repository> </repositories> Exigen Services confidential 30
  • 29. Develop with pleasure! IDE INTEGRATION Exigen Services confidential 31
  • 30. IDE list • InteliJ IDEA from 7.0 • Eclipse (plug-in: “m2eclipse”) • NetBeans 6.5 Exigen Services confidential 32
  • 31. IDE features • POM editor • Dependency synchronization • Lifecycle build runners Exigen Services confidential 33
  • 32. Let’s summarize CONCLUSION Exigen Services confidential 34
  • 33. Advantages (vs. Ant) • Know Maven – can build project • Dependency management • Less CM activities • Force to standardization • Readable pom.xml • High reusability Exigen Services confidential 35
  • 34. Disadvantages (vs. Ant) • Understanding • Artifacts search • Plug-ins documentation • “Exotic things” - maven-ant-plugin • Difficult to move from Ant Exigen Services confidential 36
  • 35. Maven repositories • Central http://repo1.maven.org/maven2/ • Central repository Explorer http://mvnrepository.com • Collection of plugins for Maven 2 http://mojo.codehaus.org • JBoss http://repository.jboss.com/maven2/ • Sun http://download.java.net/maven/2/ • Atlassian http://repository.atlassian.com/maven2/ Exigen Services confidential 37
  • 36. References • Maven site http://maven.apache.org • Quick guide http://maven.apache.org/guides/MavenQuickReferenceCard.pdf • Maven FAQ http://docs.codehaus.org/display/MAVENUSER/FAQs-1 • Better Builds with Maven. John Casey and others http://www.exist.com/better-build-maven • Maven overview in Russian http://www.ibm.com/developerworks/ru/edu/j-mavenv2/index.html • m2eclipse plug-in http://m2eclipse.codehaus.org Exigen Services confidential 38
  • 37. Now it’s your turn… QUESTIONS Exigen Services confidential 39

Editor's Notes

  1. TODO: replace screen-shot to generalize examples groupId, artifactId