MAVEN- The Building Tool

MAVEN- The Building Tool

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-

  1. 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.

  1. 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?

  1. It makes a project easy to build.

  2. It provides project information. for example, log documents, cross-reference resources, mailing lists, dependency lists, and unit tests.

  3. 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-

  1. Generate source code

  2. Generate documentation from source code

  3. Convention over configuration

  4. Compiles the source code

  5. Install the package code in the local repo/ server repo/ central repo.

POM (Project Object Model)-

  1. POM refers to the XML files that have all the information regarding project and configuration details.

  2. The main configuration file is pom.xml.

  3. 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.

  4. POM XML contains metadata, dependencies, kind of projects, kind of output, and descriptions.

Maven Directory Structure-

Maven Build Lifecycle-

  1. generate resources

  2. Compile code

  3. Unit test

  4. package (Build)

  5. Install (into Local repo and satisfactory)

  6. Deploy (to server)

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