0% found this document useful (0 votes)
11 views

Module-5 Maven (1)

Maven is a build automation and project management tool hosted by the Apache Software Foundation, primarily used for Java projects. It simplifies dependency management by allowing users to specify required libraries in a pom.xml file, which Maven uses to automatically download and manage these dependencies. The tool operates through a defined lifecycle with various phases, ensuring efficient project deployment and management.

Uploaded by

mdivyansh866
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Module-5 Maven (1)

Maven is a build automation and project management tool hosted by the Apache Software Foundation, primarily used for Java projects. It simplifies dependency management by allowing users to specify required libraries in a pom.xml file, which Maven uses to automatically download and manage these dependencies. The tool operates through a defined lifecycle with various phases, ensuring efficient project deployment and management.

Uploaded by

mdivyansh866
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Amity School of Engineering & Technology (CSE)

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 uses conventions for build procedures and only exceptions


need to be written down
- An XML file describes the software project that is built, its
dependencies on other external modules and components, the
built order, the directories and required plugin.
Amity School of Engineering & Technology (CSE)

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

Public repository can also be updated

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 ---

Maven will look for a file in Central Repository ---

If a file is present in Central Repository it will copy into the local


machine and if not then it will fetch the file from the remote
repository via the Internet.
Amity School of Engineering & Technology (CSE)

Maven Life Cycle –


to deploy & distribute target project
Amity School of Engineering & Technology (CSE)

Clean Life Cycle

CLEAN PROJECT REMOVES ALL FILES IT WORKS IN 3


BY PREVIOUS BUILT PHASES
Amity School of Engineering & Technology (CSE)

Default life cycle

MAIN LIFE CYCLE RESPONSIBLE FOR IT HAS 23 PHASES


PROJECT DEPLOYMENT
Amity School of Engineering & Technology (CSE)

Site Lifecycle

Needed for site documentation

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)

Important phases in the default life cycle


Amity School of Engineering & Technology (CSE)

Phases of Default life cycle


Validate Checks if all the information necessary for the build is available;

Compile Compiles the source code of the project

Compiles the test source code


Test compile
Responsible for running the unit test of the application

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

Install Install the package to a local repository

Deploy Copy the package to a remote repository


Amity School of Engineering & Technology (CSE)

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>

MVN Repository-> Spring -> copy dependency details


and copy to pom.xml
Amity School of Engineering & Technology (CSE)

Maven Coordinates (GAV)


• The following three fields act like an address and
timestamp.
– groupID
– artifactID
– Version
• http://maven.apache.org/pom.html#Maven_Coordinate
s
Amity School of Engineering & Technology (CSE)

Maven Tutorial Practical


• https://www.youtube.com/watch?v=uEYjXpMDJiU
Amity School of Engineering & Technology (CSE)

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.

It contains default values for most projects.

Example- build directory (target), source directory(src/main/java), test directory


(src/test/java)

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)

Create a New Maven Project


• Click on New Project.
• Select Maven on the left panel.
• Choose a Project SDK (JDK):If you don’t have one configured,
click Add JDK and select the JDK installed on your system.
• In the New Project Wizard, check Create from archetype.
• Select maven-archetype-quickstart (for a simple Java project).
• Click create.
Amity School of Engineering & Technology (CSE)

Understanding Project Structure


Amity School of Engineering & Technology (CSE)

Open and Configure pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<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)

Build the Maven Project


• Open the Maven tool window:View → Tool Windows →
Maven.
• Click the Refresh button to load the pom.xml
dependencies.
• Expand Lifecycle and double-click compile.
Amity School of Engineering & Technology (CSE)

Run the Project


• Navigate to src/main/java/com/example/App.java.

public class App


{
public static void main( String[] args )
{

System.out.println( "Hello World!" );


}
}
• Right-click on App.java → Run 'App.main()'.
Amity School of Engineering & Technology (CSE)

Package the Project into a JAR


• Open Maven Tool Window.
• Expand Lifecycle → Double-click package.
• After execution, check the target/ directory. You'll find:
• Demomaven-1.0-SNAPSHOT.jar
Amity School of Engineering & Technology (CSE)

Add External Dependencies


• Maven manages dependencies via the Central
Repository
Amity School of Engineering & Technology (CSE)

Super POM
• http://maven.apache.org/guides/introduction/introductio
n-to-the-pom.html

You might also like