Maven Tutorials

What is Maven?

Maven is a powerful build automation tool that is primarily used for java based projects maven address two critical aspects of building software first it describes how software is built and second it describes dependencies it uses conventions for build procedure and only exception need to be written down an XML file describes the software project that is building its dependencies on the other external modules and components the build other directories and the required plugins it comes with predefined targets for performing certain well-defined tasks such as compilation of code and its packaging maven.

Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project

  • Project of Apache Software Foundation
  • Build Automation tool
  • Project Management tool

Maven is a software project document management and compression. Based on the concept of POM (Project Object Management). Maven is used for build software reporting and documents. Maven is a very powerful project management tool or we can be called a build tool that helps building and documentation and managing a project.

Why do we need Maven?

New programs especially for java programmers think why do we need maven for building projects when we have an eclipse. So what eclipse is is nothing but an ID (Integrated development environment) eclipse provides an environment for developing your project. It doesn’t build your code but maven is for building code. Suppose you are working on java projects they require you to work with third-party libraries you need dependencies for the project. Dependencies not nothing but the libraries or jar files.

Suppose you are working on the java 8 version and for some reason, you need to upgrade your project to the java 9 version in this case you again need to download and add these dependencies for the latest software version, so this is not at all a good practice where you have to do things manually, so this is where maven makes your life easier maven can solve all your problems related to dependencies.

Maven Architecture

Maven Architecture

In the above diagram, these are the various components of maven architecture. This is a local repository of the local machine that you work on this is the central repository and this the remote repository or the remote web-server, so whenever you specify any dependency in the palm.XML file of maven. Maven will look for the file in the central repository. If the dependence is present in the central repository maven will copy that dependence onto your local machine but if it is not present here maven will fetch it from the remote repository using the internet, so the internet is very much mandatory for using maven this is how maven architecture works.

The Maven build follows a specific life cycle to deploy and distribute the target project.

There are three built-in life cycles:

  • default: the main life cycle as it’s responsible for project deployment
  • clean: to clean the project and remove all files generated by the previous build
  • site: to create the project’s site documentation

Maven Lifecycle

Maven Lifecycle

Maven build follows a life cycle to deploy and distribute the target project three built-in life cycles are the default, clean, and site. The default is the main life cycle as it is responsible for the project deployment. The clean life cycle is used for the project and removes all the project files by the previous build and the site is used to create the project’s site documentation. Each life cycle consists of a sequence of phases the default build life cycle consists of 23 phases as it is the main build life cycle of a maven on the other hand the clean life cycle consists of 3 phases and the site life cycle consists of 4 phases.

Maven phases and Goals:

  • A phase can have zero or more goals associated with it.
  • A life cycle is a series of phases leading up to a package type.
  • Phases are ordered and require successful completion of prior phases.
  • The default life cycle is for jar files and consists of phases that run the following goals
  • Maven can be bound to build life cycle phases

What Maven Does:

  • It simplifies the process of building the project
  • The task of downloading jar files and other dependencies does not need to be done manually
  • It provides easy access to all the required information
  • Apache maven helps manage all the processes, such as building, documentation, releasing, and distribution in project management.

What is the Build Tool:

A Build tool takes care of everything for building a project. It generates a source code Build tool is essential for the process of building it is needed for following processes.

  • It generating a source code.
  • It generating documentation from the source code.
  • It Compiling of source code.
  • It packaging of the complied code into JAR files.
  • It installing the packaging code in local repository, server or central repository.

What is Project Object Model (POM):

A Project Object Model or POM is a building block in maven it is an XML file that contains information about the project and configuration details used by maven to build a project. When we tend to execute a task, Maven searches for the POM in the current directory.

POM contains information about the project and various configuration details. It also includes goals and plugins using by maven in a project. Maven looks for the POM for the current directory in executing a task or a goal it reads the POM gets the needed configuration and then runs the code.

Java Installation

Step:1

Java Installation Step1

Step:2

Java Installation Step2

Step:3

Java Installation Step3

Step:4

Java Installation Step4

Step:5

Java Installation Step5

Step:6

Java Installation Step6

Java Installation Step6

Step:7

Java Installation Step7

JAVA is successfully installed on your machine.

Maven Installation on Local Machine

Step: 1

Maven Installation on Local Machine Step1

Step: 2

Open windows property

Maven Installation on Local Machine Step2

Step: 3

Maven Installation on Local Machine Step3

Step: 4

Maven Installation on Local Machine Step4

Click on New

Maven Installation on Local Machine Step4

Add the path of your Maven file in variable value.

Maven Installation on Local Machine Step4

Double click on the path.

Maven Installation on Local Machine Step4

Now you can see the maven version in Command prompt.

By using mvn -version

Java Installation on Ubuntu

Step 1:

apt install default-jre

Java Installation on Ubuntu Step1

Step 2:

apt install openjdk-11-jre-headless

Java Installation on Ubuntu Step2

Step 3:

apt install openjdk-8-jre-headless

Java Installation on Ubuntu Step3

Step 4:

sudo apt install default-jre

Java Installation on Ubuntu Step4

Step 5:

java -version

Java Installation on Ubuntu Step5

JAVA is successfully installed on ubuntu

Maven Installation on Ubuntu

Step 1:

apt update -y

Maven Installation on Ubuntu Step1

Step 2:

apt install maven -y

Maven Installation on Ubuntu Step2

Step3:

maven -version

Maven Installation on Ubuntu Step3

0 Comments

Submit a Comment

Your email address will not be published.