Maven is an automation and project management tool. It is developed by Apache Software Foundation. It is based on POM (Project Object Model). maven can build any number of projects into the desired outlook such as .Jar, .war and metadata.
It is mostly used by Java-based projects. Released in 2004. The meaning of maven is, "Accumulation of knowledge". Maven helps in getting the right jar file for each package as there may be a different versions of separate packages.
Dependencies- These refer to the Java libraries better needed for the project.
Repositories- Refers to the directories of package jar files.
Build Tools-
c, c++ -> make file
.net -> V.S.
Java -> Ant, Maven, Graddle
Problems without Maven-
- Adding a set of jars in each product-
In the case of Structs, we need to add jar files in each project. It must include all the dependencies of jars also.
- Creating the right project structure-
Create the right project structure in servlet, structs, etcetera. Otherwise, it will not be executed. For example, the .war file layout
3. Building and deploying the project-
We must have to build and deploy the project so that it may work.
What does Maven do?
It makes a project easy to build.
It provides project information. for example, log documents, cross-reference resources, mailing lists, dependency lists, and unit tests.
Easy to add new dependencies. Therefore Apache Maven helps to manage build dependencies, reports, releases and distribution.
What is Build Tool?
Build tool takes care of everything for building a process.
It does the following activities-
Generate source code
Generate documentation from source code
Convention over configuration
Compiles the source code
Install the package code in the local repo/ server repo/ central repo.
POM (Project Object Model)-
POM refers to the XML files that have all the information regarding project and configuration details.
The main configuration file is pom.xml.
It has a description of the project, and details regarding the versioning and configuration management of the project. The XML file is in the Project home directory.
POM XML contains metadata, dependencies, kind of projects, kind of output, and descriptions.
Maven Directory Structure-
Maven Build Lifecycle-
generate resources
Compile code
Unit test
package (Build)
Install (into Local repo and satisfactory)
Deploy (to server)
Clean (delete all runtime files)
e.g.
mvn clean package
The build life cycle consists of a sequence of build phases and each build phase consists of a sequence of goals.
Each goal is responsible for a particular task.
When a phase is run, all its goals related to that phase and its plugins are also compiled.