Maven Introduction – Part 1

Maven is a software project management and comprehension tool, an open source project by the Apache community. It can also model a standard structure for Java projects. With Project Object Model (POM) approach, Maven provides a uniform and radical way of understanding and building Java project, reporting and documentation with all its dependencies.

This tutorial will go through quite a few Maven concepts with Eclipse IDE so that we can have a better understanding about its standards.

I. Why Maven

With Maven, we can:
– open the project definition in different development environments and continuous integration tools.
– monitor the dependencies and secure their access.
– have a uniform directory structure within the project hierarchy.
– build a self-tested software with self-tested components.

So, our project is reusable, secure, and testable.

II. Maven Project with Eclipse

Create new Maven Project, we can see that the following directory structure has been created in Package Explorer:
maven-project-structure

1. Standard directory structure

project home contains pom.xml and all sub directories.
src/main/java contains the deliverable Java sourcecode.
src/main/resources contains the deliverable resources, such as property files.
src/test/java contains the testing Java sourcecode (such as JUnit or TestNG test cases).
src/test/resources contains resources necessary for testing.
JRE System Library is Java Runtime Environments library which are used to run and debug java programs.

2. Project Object Model

We configure Maven Project using Project Object Model stored in a pom.xml. POM is the basic unit of work in Maven that contains every important piece of information about project. It is good for finding anything related to the project.

Open pom.xml, we will see:

project is the top-level element in pom.xml.
modelVersion indicates what version of the object model which is using. It is important to ensure stability if the Maven developers deem it necessary to change the model.
groupId specifies the unique identifier for the organization or group who created the project. It is typically based on the fully qualified domain name.
artifactId indicates the unique identifier for the project, generally, name of the project (for example, maven-introduction).
packaging specifies the package type to be used by the artifact (JAR, WAR,…). Default value for the packaging is JAR, so we do not have to specify in the code above.
version indicates the version of the artifact generated by the project. Maven helps us with version management, we often see the SNAPSHOT which implies that the project is in state of development.
name is the display name used for the project.
description provides a lean description of the project.

The POM above is called minimal POM.
Now click Effective POM tab, we can see another type of POM called Super POM – a parent of POMs. That means the configuration specified in the Super POM is inherited by the POM which is created for the project.

Super POM

Super POM is Maven’s default POM. All POMs will extend the Super POM unless we set explicitly.

Now we can see the default project source directory structure, output directory, repositories, plug-ins, reporting directory which will be used.

These Maven concepts: Repositories, Plug-ins, Dependencies will come to you in next articles.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*