Maven is a Java mission administration software primarily based on a Venture Object Mannequin (POM). It’s an open supply mission that enables mission managers and builders to create, construct, handle, and check software program improvement initiatives. This programming tutorial discusses why – and the way – it is best to use Maven as your mission administration software program.
Advantages of Maven as a Venture Administration Device
As a developer, you could determine to construct your initiatives from scratch; nonetheless, this can be a time consuming and tiring course of. Listed here are some options that Maven possesses that may show you how to ease mission improvement and higher handle your software program improvement course of.
Dependency Administration
Maven’s Dependency Administration function is without doubt one of the greatest the reason why programmers ought to think about using Maven as your PM software of selection. In case you are creating a giant mission, the problem of managing your dependencies shortly turns into a difficulty. Maven has a central repository that permits you to simply obtain and replace dependencies.
Developer Collaboration
Utilizing a mission administration software like Maven offers mission managers (and their groups) many advantages. Maven offers you with an ordinary listing construction for quite a lot of initiatives. This, in flip, ensures simple collaboration between distributed and distant builders, IT assist, and stakeholders of your staff. Under is the usual Maven listing construction.
src | |___main | |___test | |___it | |___assembly | |___site
Simple Venture Setup
Maven offers a mission templating software known as Archetype to simply arrange initiatives. Archetypes are pattern initiatives which you could obtain and use as a reference for modeling your personal software program improvement mission. Say you wish to develop a RESTful internet API utilizing Jersey. You’ll be able to merely verify Maven’s archetype listing for reference setup of the mission.

The way to Set up Maven
There are a variety of how in which you’ll be able to set up Maven: both by the terminal or out of your Eclipse IDE.
It’s a lot simpler for builders to work together with Maven utilizing Eclipse. Subsequently, this tutorial will deal with this strategy. To learn to set up and configure Maven from the terminal, try our tutorial: Getting Began with Maven.
Earlier than studying the way to set up Maven on Eclipse, you will need to perceive that there are several types of Eclipse code editors. In case you are utilizing Eclipse IDE for Enterprise Java and Internet Builders, then Maven ought to already be put in.
In case you are utilizing Eclipse IDE for Java Builders (the almost certainly state of affairs), then you may verify the Eclipse market for the Maven Plugin. You are able to do so by going to Assist > Market after which looking for m2eclipse or following this hyperlink.

Instance of Eclipse Market
The way to Create a POM File
First, let’s learn to create a brand new Maven mission. Click on File > New > Maven Venture
You will note a dialog field pop-up just like the one beneath:

Subsequent, let’s select Create a easy mission. After checking this field, click on Subsequent. It’s best to have a dialog field just like the one beneath:

The group id (for instance, com.developer) specifies the package deal wherein the mission will likely be. The Artifact Id (for instance, webapp) is the title of the mission listing. Identify is the title of the mission. After coming into these fields, press End.
Now, let’s focus on the POM (Venture Object Mannequin) file. POM is an XML file that specifies mission particulars corresponding to dependencies, plugins, or construct profiles. It determines how Maven builds totally different elements of your mission.
The minimal necessities for a POM file are as follows:
- mission: That is the foundation aspect of the POM file
- modelVersion: That is the at the moment supported POM model. On the time of this writing, model 4.0.0 is the one one supported
- groupId: This defines the listing ID of your mission. By conference, that is normally the reverse of your website’s area title
- artifactId: That is the title of mission’s listing
- model: The model of your artifact/mission beneath the given group
Right here is the pattern POM file that was created from the directions on this part:
<mission xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.developer</groupId> <artifactId>webapp</artifactId> <model>0.0.1-SNAPSHOT</model> <title>Article</title> </mission>
Yours might look totally different relying in your system settings and once you created the file (for instance, if a more moderen model of Maven exists at the moment).
The way to Construct and Deploy Initiatives in Maven
Earlier than discussing how one can construct your software program mission, it might be unfair to finish this tutorial with out speaking about the way to use dependencies. To outline dependencies in your POM file, use the dependencies tag. On this tag, you may checklist every dependency that you just want utilizing the dependency tag.
Right here is an instance of the servlet API dependency in Maven:
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <model>2.5</model> </dependency>
You could be questioning the way to get the values for the groupId or model to make use of. You’ll be able to navigate to the POM file for the actual dependency you need from the Maven central repository.
Lastly, to construct your mission, right-click on the mission folder out of your Eclipse editor. Select Run as > Maven Construct….. Within the field for Venture objectives, enter clear set up. It will be sure that all of your mission dependencies are downloaded. Guarantee that you’ve got an lively Web connection whereas all that is happening.
Closing Ideas on Maven Dependency Administration
Maven is a free software program beneath the Apache Software program Basis. It eases the work of mission administration by automating some processes as you create, construct, check, and deploy your mission. In case you are engaged on a big Java mission, for instance, it is best to definitely think about using Maven.
Venture Administration Instruments for Builders
Whereas Maven is a good software for managing software program improvement initiatives, dependencies, and code repositories, in addition to for permitting collaboration with different programmers, it could not fit your actual wants as a real mission administration software. If you end up in search of mission administration software program with options like superior reporting, problem and bug monitoring, Kanban boards, Gantt charts, and file sharing, we recommend you check out our checklist of the Prime Venture Administration Software program and Instruments for Builders for different choices.