Installation and Setup

1. Download Maven . Click here

2. Set environment variables as shown in the screenshot

1. Add maven path in the Path Variable

2. Create new system variable MAVEN_OPTS

-Xms256m -Xmx512m

Image for post
Image for post
Image for post
Image for post

3. Validate if maven is installed successfully. Run mvn — version

Create Maven Project

  1. Create a directory on your system
  2. Run mvn archetype:generate ( This is used to setup a package structure for particular project type)
  3. There are different number for different type of project structure. 1092 — is the sample Maven project
  4. groupId — package structure
  5. artifactID — Project Name
  6. This command has created a java project directory structure with pom.xml file
Image for post
Image for post
Image for post
Image for post

6. pom.xml file

<project xmlns=”" xmlns:xsi=”"





Build LifeCycle

  1. validate
  2. compile
  3. test
  4. package
  5. install
  6. deploy

To compile the project, run

mvn compile

To generate a jar, run

mvn package ( This will always do the validate ,compile,test and then package) This applied to all build life cycle, it always execute in the order only whichever command you run. for example mvn compile, only phases up to and including that phase will execute.

Setup of MultiModule Project

We have 2 modules (simple-weather and simple-webapp). There is one parent pom.xml and two which are module specific inside both the folders. Here the packaging tag doesnt have a jar/war, instead of it is pom.

Image for post
Image for post

Parent POM.xml

It is referencing one ore more submodules as highlighted in the below pom.xml

<?xml version=”1.0" encoding=”UTF-8"?>
<project xmlns=”"
<name>Multi Chapter Simple Parent Project</name>


Child pom.xml will have a reference to the parent


Dependency Scopes


compile is the default scope; all dependencies are compile-scoped if a scope is not supplied. compiledependencies are available in all classpaths, and they are packaged.


provided dependencies are used when you expect the JDK or a container to provide them. For example, if you were developing a web application, you would need the Servlet API available on the compile classpath to compile a servlet, but you wouldn’t want to include the Servlet API in the packaged WAR; the Servlet API JAR is supplied by your application server or servlet container. provided dependencies are available on the compilation classpath (not runtime). They are not transitive, nor are they packaged.


runtime dependencies are required to execute and test the system, but they are not required for compilation. For example, you may need a JDBC API JAR at compile time and the JDBC driver implementation only at runtime.


test-scoped dependencies are not required during the normal operation of an application, and they are available only during test compilation and execution phases.


The system scope is similar to provided except that you have to provide an explicit path to the JAR on the local file system. This is intended to allow compilation against native objects that may be part of the system libraries. The artifact is assumed to always be available and is not looked up in a repository. If you declare the scope to be system, you must also provide the systemPath element. Note that this scope is not recommended (you should always try to reference dependencies in a public or custom Maven repository).

Image for post

Devops Automation Enginneer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store