Welcome to linuxnix.com. We have already covered the basics about Maven. In this blog, we are going to know more about it. We will focus on the types of Maven repositories, deep into POM, how Maven works, etc. If you want to understand the basics of Maven, click here.


Maven Overview


Super POM

The Super POM is the Maven’s default POM which is also called as Parent POM or Base POM. This is usually placed on the root directory of the project and there can be multiple subprojects which can have multiple POMs. These POMs from the subprojects are called Child POMs.

An easy way to look at the default configurations of the super POM is by running the following command.

mvn help:effective-pom


The minimum requirement for POM

There are few minimal requirements for POM without which Maven cannot parse POM while building.

  1. Project root
  2. Model Version
  3. GroupId
  4. ArtifactId
  5. Version

Maven uses the configuration from Super POM plus project configuration to execute the task. It runs sensible default behavior for projects, when the project is created it creates default structure. Developers are required only to place files in the respective location and no need to define any configuration in POM.xml. Below shows the default path:

  • Source code: <project-location>/src/main/java
  • Resources: <project-location>/src/main/resources
  • Tests: <project-location>/src/test
  • Complied byte code: <project-location>/target
  • Distribution JAR: <project-location>/target/classes.


Maven Directory Structure

The directory structure of an ideal Maven project has the following directory entries:

Directory namePurpose
project homeContains the pom.xml and all subdirectories.
src/main/javaContains the deliverable Java source code for the project.
src/main/resourcesContains the deliverable resources for the project, such as property files.
src/test/javaContains the testing Java source code (JUnit or TestNG test cases, for example) for the project.
src/test/resourcesContains resources necessary for testing.


Maven Settings File

Maven has two settings file. In these files, you can configure settings for Maven across all Maven POM files. For instance, you can configure the location of the local repository, the active build profile, etc. The setting files are settings.xml and are located in these two locations:

  1. The Maven installation directory: $M2_HOME/conf/settings.xml
  2. The user’s home directory: ${user.home}/.m2/settings.xml

The files are optional. If both files are present, the values in the user’s home setting file override the value in Maven installation settings file.


Maven Repositories

For Maven to download required artifacts of the build, dependencies and other plugins which are configured as the part of the project, there should be a commonplace. This common shared area is called Maven Repository. Maven has mainly three types of repositories.

  1. Local repository
  2. Central repository
  3. Remote repository

Maven searches all these three repositories for dependencies in the above sequence. First in the local repository, then in the central repository and finally in the remote repository, if specified in the POM.


Maven Local Repository

The Local repository is the directory on the developer’s computer. This directory contains all the dependencies Maven downloads. The same maven repository is used for several different projects. The Maven just need to download the dependency once.

By default, maven keeps the local repository under user-home/.m2 directory. The path can be changed by changing the configuration of the settings file. Below is an example.



Maven Remote Repository

This repository is situated on the web server from which Maven can download dependencies. It can be located anywhere on the internet or inside a local network. This repository is often used to host projects internal to your organization, which are shared by multiple projects.

Even common security policies can be implemented across the organization which can be shared by multiple projects. It can be hosted in a private network where the developers form an organization will only have the access to use it.


Maven Central Repository

The Maven Central repository is the repositories provided by the Maven community. By default, Maven searches the dependencies in the local repository. When not found, it searches it in the Central repository.

You don’t need any special configuration to access Central repository. Many developers use the predefined dependency from here and even contribute back to the community.



So, In this blog, we went deeper into Maven and understood various part of Maven and their functionalities. In our next blog, we will go deep into some practical sets where we will undergo the installation, the life cycle of maven build and all the Maven commands. If you wish to go through the Maven basics, click here.

Stay tuned with linuxnix.com.


The following two tabs change content below.
Hello, my name is Ankesh and I work as a Sr. DevOps Engineer in an IT firm where I have hands-on experience in supporting and automating deployments in the cloud, leveraging configuration management and DevOps process. I like to keep myself always in the learning path and love to share knowledge with others. One of my other interests is Graphics Designing and my hobbies are Cooking and Playing Cricket.