Module-5 Maven (1)
Module-5 Maven (1)
MAVEN
Amity School of Engineering & Technology (CSE)
What is Maven?
• Hosted by Apache Software Foundation
• While Eclipse is an IDE that provides environment for developing
project, Maven is used for building the code
• Traditionally for software development in Java we need to use third
party libraries or dependencies or libraries (jar files) to execute Spring
or hibernate
• Spring needs 10-12 libraries that need to downloaded and add them
manually. Further, in case of version change, this step must be repeated.
• Maven relieves you from this
Amity School of Engineering & Technology (CSE)
Contd…
• Maven solves the problem related to dependencies.
• You just need to specify the dependencies that you need in
pom.xml file
• In case of version change, you just need to change pom.xml
• Maven is a build automation tool
• Maven is a project management tool
• Maven handles the complete build process
Amity School of Engineering & Technology (CSE)
Contd…
Maven is used for Java based project and addresses two critical
aspects of building software
(i) Describes how software is built
(ii) Describe the dependencies
Maven
It comes with pre-defined targets for performing well-defined tasks such as compilation
of code and its packaging
Maven dynamically downloads java libraries and maven plugins from one or more
repositories such as maven central repository and stores in local cache.
This local cache of the downloaded artifacts can also be updated with the artifacts
created with the local repository
Maven can also be used to build and manage projects written in c#, scala etc
Amity School of Engineering & Technology (CSE)
Maven Architecture
Amity School of Engineering & Technology (CSE)
Contd…
When you specify a dependency in pom.xml file of maven ---
Site Lifecycle
It has 4 phases
Amity School of Engineering & Technology (CSE)
Contd…
• A lifecycle is organized into
sequence of phases.
• Each phase is responsible
for a specific task.
• Phases give order to a set of
goals.
• These goals are chosen and
bound by the packaging type
of the project being acted on
Amity School of Engineering & Technology (CSE)
Packaging the compiled source code into the distributable format (i.e
Packaging jar format)
Integration In this phase the process and deployment of the package is needed
Lifecycle->Phases-> Goals
Plug-in are mapped to goals and executed as part
of goals
Amity School of Engineering & Technology (CSE)
Process
Project -> Anything that we create in Maven
Pom.xml is the main file where we describe the dependencies
<project xmlns….
<dependency>
<groupID> com.supriya //unique identifier
<artifactID> demo
<version>
Amity School of Engineering & Technology (CSE)
Contd…
<dependency>
<groupID> org.Springframework </groupID>
<artifactID> Spring-xyz </artifactID>
<version> 4.3.8 release </version>
What is POM?
A Project Object Model or POM is the fundamental unit of work in Maven.
It is an XML file that contains information about the project and configuration details used
by Maven to build the project.
When executing a task or goal, Maven looks for the POM in the current directory. It reads
the POM, gets the needed configuration information, then executes the goal
Amity School of Engineering & Technology (CSE)
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Demomaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<!-- Example: JUnit dependency for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Amity School of Engineering & Technology (CSE)
Super POM
• http://maven.apache.org/guides/introduction/introductio
n-to-the-pom.html