SlideShare una empresa de Scribd logo
1 de 23
An Introduction to
     Maven
What is Maven
●   A build tool.


●   A Project Management Tool.


●   An abstract container for running Build Tasks.


●   A tool providing guidelines for best practice development.
What is Maven(Contd.)
●   It is a tool to manage applications that graduate beyond simple and
    need to start finding consistent ways to manage and build large
    collections of independent modules and libraries which make use of
    tens of hundreds of third-party components.


●   According to the official definition -
            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. When you use
             Maven, you describe your project using a well-defined
             project object model, Maven can then apply cross-cutting
             logic from a set of shared (or custom) plugins.
Convention over Configuration
●   Maven incorporates this concept by providing sensible default
    behavior for projects.


●   It goes further than just simple directory locations. Maven's core
    plugins apply a common set of conventions for compiling source
    code, packaging distributions, generating websites, and many other
    processes.


●   However, most of the defaults provided by Maven can be customized.
Conceptual Model of a Project
●   Maven maintains a model of project. It does not just compile source
    code into bytecode, it develops a description of a software project and
    assigns a unique set of co-ordinates to a project.


●   It helps to mange project's license, the developers and contributors to
    the project, other dependent sub-projects etc.
Installing Maven
●   Verify that you've installed Java in your system.


●   Download Maven.


●   Set up Maven (remember to set up JAVA_HOME and
    MAVEN_HOME, and add maven home directory to PATH).


●   Test your installation (mvn –version in Windows).


●   Google it if any problem occurs/ask in our group channel.
Creating a Simple Project
●   We will use the Maven Archetype plugin to generate a simple skeleton
    project.


●   Open up your command prompt/shell, go to a particular location
    where you want the project to be stored, and execute the following
    command and keep hitting ENTER for now to accept the default
    options. The whole command should be typed in one line -
            mvn archetype:generate -DgroupId=org.wikiengine.intro
             -DartifactId=intro -Dpackage=org.wikiengine.intro
             -Dversion=1.0-SNAPSHOT


●   Please be patient. It will require considerable amount of time to
    complete. You will also need internet connection.
Creating a Simple Project(Contd.)
●   An Archetype is defined as -
            An original model or type after which other similar things are
              patterned; a prototype.


●   A number of archetypes are available in Maven for anything from a
    simple Swing Application to a complex web application, and the
    archetype:generate offers a huge list of archetypes to choose from,
    which you just did when you kept hitting ENTER. Here, archetype is
    the plugin prefix, and generate is called a GOAL.
Generated Project Skeleton
●   Open up the intro folder. The directory structure should look
    something like this -
         ●   intro
                     ●   src
                               –   main
                                          ●   java
                                                     ●   ….
                                                              ●   App.java
                               –   test
                                          ●   java
                                                     ●   …
                                                              ●   AppTest.java
                     ●   pom.xml
Generated Project Skeleton(Contd.)
●   The Maven Archetype plugin creates a directory called intro that
    matches the artifactId. This is known as the project's Base Directory.


●   Every Maven project has what is known as a Project Object Model,
    or, POM, for short, in a file named pom.xml. This file describes the
    project, configure plugins, and declare dependencies.


●   Project's source code and resources are placed under src/main. This
    folder may contain some simple java classes and some properties file,
    or it may be the document root of a web application, or it may contain
    configuration files for an application server (remember Glassfish,
    anyone?). In a java project, Java classes are placed in src/main/java
    and classpath resources are placed in src/main/resources.
Generated Project Skeleton(Contd.)
●   Project's test cases are located in src/test. Under this directory, Java
    classes such as JUnit tests are placed in src/test/java, and classpath
    resources for tests are located in src/test/resources.


●   For the time being, the Maven Archetype plugin has generated a
    single Java class org.wikiengine.intro.App, which is a pretty simple
    Hello World program.
Building and Running the Project
●   Once again, open up your command prompt/shell and traverse into the
    project's Base Directory, which is intro in our case. Then execute the
    following command -
            mvn install

●   Be patient, it will take considerable amount of time in this case too.
    Also you will need to be connected to the internet.


●   After your build is successful, run the program to test it -
            java -cp target/intro-1.0-SNAPSHOT.jar
              org.wikiengine.intro.App
The POM File
●   Take a look at the generated pom.xml file. This is the most basic POM
    we will ever deal with for a Maven project, usually a POM is
    considerably more complex.


●   The first few elements – groupId, artifactId, packaging, version – are
    what is known as the Maven co-ordinates which uniquely identify a
    project.


●   name and url are descriptive elements of the POM providing a human
    readable name and associating the project with a web site.


●   The dependencies element defines a single, test-scoped dependency
    on a unit testing framework called JUnit.
The POM File(Contd.)
●   Maven will always execute against an effective POM. This effective
    POM is constructed from the current project's pom.xml, all parent
    POMs, a super-POM defined within Maven, user-defined settings, and
    active profiles. All projects ultimately extend super-POM, which
    defines a set of sensible default configuration settings.


●   To see the effective POM, run the following command in the project
    base directory -
           mvn help:effective-pom

●   You should see a much larger POM which exposes the default settings
    of Maven. This can come in handy while debugging.
What Have We Done So Far
●   A project is generated which consisted of a POM and some code
    assembled in the Maven standard directory layout. We generated this
    project by executing a plugin goal.


●   We then executed Maven with a lifecycle phase as an argument,
    which prompted Maven to execute a series of Maven plugin goals.


●   Lastly, we have installed a Maven artifact into our local repository.
Goals
●   Goals are unit of work in Maven. A goal is a specific task that
    contributes to the building and managing of a project. Goals may be
    executed as a standalone goal or along with other goals as part of a
    larger build.


●   Examples of goals include the compile goal in the Compiler plugin,
    which compiles all of the source code for a project, or the test goal of
    the Surefire plugin, which can execute unit tests.


●   When referring to a plugin goal, we often use the shorthand notation:
    pluginId:goalId (remember our archetype:generate portion of the
    command before?).
Goals(Contd.)
●   They define parameters that contain sensible default values. In our
    example, the goal stopped for some input from us because there were
    no sensible defaults for this case. If we had run the archetype:create
    goal, Maven would have assumed that we wanted to generate a new
    project using the default maven-archetype-quickstart archetype. This
    is also an example of the convention over configuration principle.


●   Each goal has access to the information defined in the project's POM.
    They always execute in the context of a POM.
Plugins
●   A Maven plugin is a collection of one or more goals. Example plugins
    are Compiler, Surefire, Jar etc.


●   The Maven Core basically does nothing when it comes to project
    build. It basically knows how to parse the command line, manage a
    classpath, parse a POM file, and download Maven plugins. All other
    important tasks are taken care of by the various plugins.


●   This ensures universal re-usability of common build logics.
Maven Lifecycle
●   The second command that we've executed contained a Lifecycle Phase
    as an argument.


●   Maven is based around the central concept of a Build Lifecycle. It is a
    list of named phases that can be used to give order to Goal Execution,
    wherein a phase represents a stage in the lifecycle. Goals are chosen
    and bound by the packaging type of the project being acted upon.


●   There are three built-in lifecycles – default, clean and site. The first
    one handles project deployment, the second one handles project
    cleaning, while the last one handles the creation of the project's site
    documentation. Each of these is defined by a different list of build
    phases. To see the total list, go here.
Maven Lifecycle(Contd.)
●   The default lifecycle contains quite a lot of build phases. They are
    executed sequentially to complete the default lifecycle.


●   To fully execute a whole lifecycle, you only need to invoke the last
    build phase to be executed. This is because if you call a build phase, it
    will execute not only that build phase, but also every build phase prior
    to the called build phase. So, for the default lifecycle, executing
            mvn deploy
    will cause the whole default lifecycle phases to be executed.


●   A build phase is basically made up of various goals as plugin goals
    can be attached to it.
Maven Lifecycle(Contd.)
●   As Maven moves through the phases in a lifecycle, it will execute the
    goals attached to each particular phase. Each phase may have zero or
    more goals attached to it. If it has no goals bound to it, it will not
    execute.


●   A goal which is not bound to any build phase could be executed
    outside of the build lifecycle by direct invocation (remember
    archetype:generate, anyone? ) .


●   The lifecycle is what allows a developer to jump from one Maven
    project to another without having to know very much about the details
    of each particular project's build.
Next Meeting Topics
●   Understanding Maven Coordinates, Repositories, Dependencies.


●   Customizing Maven, managing dependencies


●   Generating complex web application, adding Java EE dependencies.


●   Managing multi-module projects.
References/Acknowledgments
●   Maven by Example by Sonatype.


●   Official Maven Documentation.


●   Our handsome guy Sharif Shahnewaz's awesome slide.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Introduction to Apache Maven
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Maven
Maven Maven
Maven
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 
Maven
MavenMaven
Maven
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Maven
MavenMaven
Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
Development Tools - Maven
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
 

Similar a An Introduction to Maven Part 1

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
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 
Apache ANT vs Apache Maven
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache MavenMudit Gupta
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenArnaud Héritier
 
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
 
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 MavenScheidt & Bachmann
 
Java build tools
Java build toolsJava build tools
Java build toolsSujit Kumar
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
 
Fundamental of apache maven
Fundamental of apache mavenFundamental of apache maven
Fundamental of apache mavenRajesh Kumar
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to MavenEric Wyles
 

Similar a An Introduction to Maven Part 1 (20)

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
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 
What is maven
What is mavenWhat is maven
What is maven
 
tools cli java
tools cli javatools cli java
tools cli java
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Apache ANT vs Apache Maven
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache Maven
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache Maven
 
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
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
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
 
Java build tools
Java build toolsJava build tools
Java build tools
 
Maven
MavenMaven
Maven
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Apache maven
Apache mavenApache maven
Apache maven
 
Fundamental of apache maven
Fundamental of apache mavenFundamental of apache maven
Fundamental of apache maven
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 

Más de MD Sayem Ahmed

Distributed systems - A Primer
Distributed systems - A PrimerDistributed systems - A Primer
Distributed systems - A PrimerMD Sayem Ahmed
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method PatternMD Sayem Ahmed
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworksMD Sayem Ahmed
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 

Más de MD Sayem Ahmed (6)

Distributed systems - A Primer
Distributed systems - A PrimerDistributed systems - A Primer
Distributed systems - A Primer
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
01. design pattern
01. design pattern01. design pattern
01. design pattern
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

An Introduction to Maven Part 1

  • 2. What is Maven ● A build tool. ● A Project Management Tool. ● An abstract container for running Build Tasks. ● A tool providing guidelines for best practice development.
  • 3. What is Maven(Contd.) ● It is a tool to manage applications that graduate beyond simple and need to start finding consistent ways to manage and build large collections of independent modules and libraries which make use of tens of hundreds of third-party components. ● According to the official definition - 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. When you use Maven, you describe your project using a well-defined project object model, Maven can then apply cross-cutting logic from a set of shared (or custom) plugins.
  • 4. Convention over Configuration ● Maven incorporates this concept by providing sensible default behavior for projects. ● It goes further than just simple directory locations. Maven's core plugins apply a common set of conventions for compiling source code, packaging distributions, generating websites, and many other processes. ● However, most of the defaults provided by Maven can be customized.
  • 5. Conceptual Model of a Project ● Maven maintains a model of project. It does not just compile source code into bytecode, it develops a description of a software project and assigns a unique set of co-ordinates to a project. ● It helps to mange project's license, the developers and contributors to the project, other dependent sub-projects etc.
  • 6. Installing Maven ● Verify that you've installed Java in your system. ● Download Maven. ● Set up Maven (remember to set up JAVA_HOME and MAVEN_HOME, and add maven home directory to PATH). ● Test your installation (mvn –version in Windows). ● Google it if any problem occurs/ask in our group channel.
  • 7. Creating a Simple Project ● We will use the Maven Archetype plugin to generate a simple skeleton project. ● Open up your command prompt/shell, go to a particular location where you want the project to be stored, and execute the following command and keep hitting ENTER for now to accept the default options. The whole command should be typed in one line - mvn archetype:generate -DgroupId=org.wikiengine.intro -DartifactId=intro -Dpackage=org.wikiengine.intro -Dversion=1.0-SNAPSHOT ● Please be patient. It will require considerable amount of time to complete. You will also need internet connection.
  • 8. Creating a Simple Project(Contd.) ● An Archetype is defined as - An original model or type after which other similar things are patterned; a prototype. ● A number of archetypes are available in Maven for anything from a simple Swing Application to a complex web application, and the archetype:generate offers a huge list of archetypes to choose from, which you just did when you kept hitting ENTER. Here, archetype is the plugin prefix, and generate is called a GOAL.
  • 9. Generated Project Skeleton ● Open up the intro folder. The directory structure should look something like this - ● intro ● src – main ● java ● …. ● App.java – test ● java ● … ● AppTest.java ● pom.xml
  • 10. Generated Project Skeleton(Contd.) ● The Maven Archetype plugin creates a directory called intro that matches the artifactId. This is known as the project's Base Directory. ● Every Maven project has what is known as a Project Object Model, or, POM, for short, in a file named pom.xml. This file describes the project, configure plugins, and declare dependencies. ● Project's source code and resources are placed under src/main. This folder may contain some simple java classes and some properties file, or it may be the document root of a web application, or it may contain configuration files for an application server (remember Glassfish, anyone?). In a java project, Java classes are placed in src/main/java and classpath resources are placed in src/main/resources.
  • 11. Generated Project Skeleton(Contd.) ● Project's test cases are located in src/test. Under this directory, Java classes such as JUnit tests are placed in src/test/java, and classpath resources for tests are located in src/test/resources. ● For the time being, the Maven Archetype plugin has generated a single Java class org.wikiengine.intro.App, which is a pretty simple Hello World program.
  • 12. Building and Running the Project ● Once again, open up your command prompt/shell and traverse into the project's Base Directory, which is intro in our case. Then execute the following command - mvn install ● Be patient, it will take considerable amount of time in this case too. Also you will need to be connected to the internet. ● After your build is successful, run the program to test it - java -cp target/intro-1.0-SNAPSHOT.jar org.wikiengine.intro.App
  • 13. The POM File ● Take a look at the generated pom.xml file. This is the most basic POM we will ever deal with for a Maven project, usually a POM is considerably more complex. ● The first few elements – groupId, artifactId, packaging, version – are what is known as the Maven co-ordinates which uniquely identify a project. ● name and url are descriptive elements of the POM providing a human readable name and associating the project with a web site. ● The dependencies element defines a single, test-scoped dependency on a unit testing framework called JUnit.
  • 14. The POM File(Contd.) ● Maven will always execute against an effective POM. This effective POM is constructed from the current project's pom.xml, all parent POMs, a super-POM defined within Maven, user-defined settings, and active profiles. All projects ultimately extend super-POM, which defines a set of sensible default configuration settings. ● To see the effective POM, run the following command in the project base directory - mvn help:effective-pom ● You should see a much larger POM which exposes the default settings of Maven. This can come in handy while debugging.
  • 15. What Have We Done So Far ● A project is generated which consisted of a POM and some code assembled in the Maven standard directory layout. We generated this project by executing a plugin goal. ● We then executed Maven with a lifecycle phase as an argument, which prompted Maven to execute a series of Maven plugin goals. ● Lastly, we have installed a Maven artifact into our local repository.
  • 16. Goals ● Goals are unit of work in Maven. A goal is a specific task that contributes to the building and managing of a project. Goals may be executed as a standalone goal or along with other goals as part of a larger build. ● Examples of goals include the compile goal in the Compiler plugin, which compiles all of the source code for a project, or the test goal of the Surefire plugin, which can execute unit tests. ● When referring to a plugin goal, we often use the shorthand notation: pluginId:goalId (remember our archetype:generate portion of the command before?).
  • 17. Goals(Contd.) ● They define parameters that contain sensible default values. In our example, the goal stopped for some input from us because there were no sensible defaults for this case. If we had run the archetype:create goal, Maven would have assumed that we wanted to generate a new project using the default maven-archetype-quickstart archetype. This is also an example of the convention over configuration principle. ● Each goal has access to the information defined in the project's POM. They always execute in the context of a POM.
  • 18. Plugins ● A Maven plugin is a collection of one or more goals. Example plugins are Compiler, Surefire, Jar etc. ● The Maven Core basically does nothing when it comes to project build. It basically knows how to parse the command line, manage a classpath, parse a POM file, and download Maven plugins. All other important tasks are taken care of by the various plugins. ● This ensures universal re-usability of common build logics.
  • 19. Maven Lifecycle ● The second command that we've executed contained a Lifecycle Phase as an argument. ● Maven is based around the central concept of a Build Lifecycle. It is a list of named phases that can be used to give order to Goal Execution, wherein a phase represents a stage in the lifecycle. Goals are chosen and bound by the packaging type of the project being acted upon. ● There are three built-in lifecycles – default, clean and site. The first one handles project deployment, the second one handles project cleaning, while the last one handles the creation of the project's site documentation. Each of these is defined by a different list of build phases. To see the total list, go here.
  • 20. Maven Lifecycle(Contd.) ● The default lifecycle contains quite a lot of build phases. They are executed sequentially to complete the default lifecycle. ● To fully execute a whole lifecycle, you only need to invoke the last build phase to be executed. This is because if you call a build phase, it will execute not only that build phase, but also every build phase prior to the called build phase. So, for the default lifecycle, executing mvn deploy will cause the whole default lifecycle phases to be executed. ● A build phase is basically made up of various goals as plugin goals can be attached to it.
  • 21. Maven Lifecycle(Contd.) ● As Maven moves through the phases in a lifecycle, it will execute the goals attached to each particular phase. Each phase may have zero or more goals attached to it. If it has no goals bound to it, it will not execute. ● A goal which is not bound to any build phase could be executed outside of the build lifecycle by direct invocation (remember archetype:generate, anyone? ) . ● The lifecycle is what allows a developer to jump from one Maven project to another without having to know very much about the details of each particular project's build.
  • 22. Next Meeting Topics ● Understanding Maven Coordinates, Repositories, Dependencies. ● Customizing Maven, managing dependencies ● Generating complex web application, adding Java EE dependencies. ● Managing multi-module projects.
  • 23. References/Acknowledgments ● Maven by Example by Sonatype. ● Official Maven Documentation. ● Our handsome guy Sharif Shahnewaz's awesome slide.