In order to understand the difficulty when we do not use the maven in Java project, there are some tasks that we have to do:

  • copy resources such as conf files to the build folder.
  • compile the source files.
  • copy dependency jars to build folder.
  • run unit tests.
  • package the build folder as jar.

To make our life easier to breath, Maven was created.

Maven is a tool for managing resource objects or package in Java. It is as same as npm in Node.js. When you want to build a enormous project, absolutely, you need maven.

Understanding some tricky things about maven will help you easily to write code, use so many packages effectively. You do not manually add many packages into your project. To configure maven, you will cope with understanding some parameter in POM file.

In this article, we will find informations about configuring POM file.

Table of Contents

Standard structure in Maven project

The below is the image about standard folder structure in maven project.

|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- com
    |   |       `-- your-company-name
    |   |           |-- config
    |   |           |   |--
    |   |           |   `--
    |   |           |
    |   |           `-- controllers
    |   |               `--
    |   |-- resources     
    |   `-- webapp     
    |       `-- WEB-INF
    |           `-- jsp
    |               `-- index.jsp 
    `-- test
        `-- java
            `-- com
                `-- your-company-name
                    `-- app

The followings is the table explains the meanings of each path in your folder structure.

Path Meanings
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/webapp Web application sources
src/main/filters Resource filter files
src/test/java Test sources
src/test/resources Resources is used for unit tests, and it will not be deployed
src/test/filters Test resource filter files
src/it Integration tests
src/site Files are used to generate the Maven project

At the top level, files descriptive of the project is a pom.xml file.

There are just two sub folders: src and target. The target directory is used to contains all output of the build. The src directory contains all the source material for building the project, its site and so on.

POM file in Maven project

A POM - Project Object Model is an xml files that contains all informations about project and configuration details used by Maven to build the project.

All our information will be contained in project tag. To be default, some parameters of project will be inserted in pom.xml.

Parameters in POM file

<project ...>

    <!-- POM relationships -->

    <!-- Project information -->

     <!-- Build Settings -->

    <!-- Build Environment -->

    <!-- Environment Information -->

    <!-- Maven Environment -->



  • groupId: a name of your company, …
  • artifactId: a name of package, project
  • version: a version of project
  • packaging: there are four values: ear, pom, jar (default value) and war. jar - library or java application; war - web application.
  • modelVersion: its value will be always 4.0.0 for Maven 2.x POMs.

Note about jar, war files:

  • .jar files: The .jar files contain libraries, resources and accessories files like property files.
  • .war files: The war file contains the web application that can be deployed on any servlet/jsp container. The .war file contains jsp, html, javascript and other files necessary for the development of web applications.


  • <version>1.0.0-SNAPSHOT</version>: The SNAPSHOT version suffix tells Maven that this project is currently in development. It has implications for the way artifacts are handled by the dependency resolution.
  • artifacts: Maven artifacts belong to a group (typically, and must have a unique identifier (typically the application’s name).
  • The main repository for Maven is called the Central Repository and can be searched on at

Add specific packages into project through pom file

In order to import many libraries into our project through Maven, insert informations about these libraries into dependencies tag in pom.xml.

properties tag helps our define many constant variables, make our do not concern about some problems when we change this value at the other places. It makes our code synchronous. It will used to tell Maven use a specified JDK version to compile the source code.

Belows are the definitions of some common packages that will use for Spring MVC.



    <!-- Spring -->

    <!--Use guava library-->
        <!-- or, for Android: -->

    <!--hibernate dependencies-->



    <!--use Log4j-->

    <!--jquery, bootstrap from webjars-->


    <!--Spring and transactions-->


    <!--Spring JDBC support-->
    <!--MySQL driver-->


    <!-- junit 5, unit test -->

    <!-- unit test -->

    <!-- for web servlet -->

    <!-- use for SHA hashing -->

    <!-- use for hibernate -->

scope tag will help our restrict the usage of libraries. Because some libraries can be used for unit testing, the other can be provided at runtime by the application server.

Maven provides four dependency scopes:

  • compile: A compile-scope dependency is available in all phases. It is the default value.
  • provided: A provided dependency is used to compile the application, but will not be deployed. You would use this scope when you expect the JDK or application server to provide the JAR. For instance, Servlet. provided dependencies are available on the compilation classpath (not runtime). They are not transitive, nor are they packaged.
  • runtime: Runtime-scope dependencies are not needed for compilation, only for executing and test the system, such as JDBC drivers.
  • test: Test-scope dependencies are needed only to compile and run tests. For instance, JUnit.
  • system: It has properties as same as 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).

  • import: It is used to import some dependency but it must be pointed in <dependencyManagement\/> tags in POM files.

How the Maven works

Firstly, we add informations about libraries that we need into dependencies tag, then, we save the pom.xml file. Maven will send these informations to its cloud repository. Next, it will download these libraries into local repository of Maven.

To check the path of this local repository, you can open User setting of Netbeans or Eclipse. Finally, Maven will add the path of each libraries into Dependencies folder in Netbeans.

And Spring Boot Maven Plugin provides some convenient features:

  • It searches for the public static void main() method to flag as a runnable class.

  • It provides a built-in dependency resolver that sets the version number to match Spring Boot dependencies. You can override any version you wish, but it will default to Boot’s chosen set of versions.

Some problems when using Maven

  1. Unable to find valid certification path to requested target

    When using command line mvn clean install for our project, we will encounter a problem that look at an below image.

    The cause of this problem:

    • This is due to the fact that we want to access the server, but Java’s security policy does not find some certificates in its security files of a folder %JAVA_HOME%\jre\lib\security.

      So, it will throw an exception.

    Solution for this problem:

    • In this case, we will use keytool that is provided by JDK.

    • To list all certificates in cacerts file, we can use the following command.

        keytool -list -keystore cacerts

      When we cope with the prompt Enter keystore password, it’s the first time that we set up password for this keytool. So we only type our password for it.

    • Then, we will connect to the server that we want to get certificates. In our current case, it is

        keytool -printcert -rfc -sslserver

      After typing this command line in cmd window, we need to save the content of these certificates in a file that is in the same folder with cacerts file.

      Assuming that we named this file that is mpdcertificates.pem file.

    • Import these above certificates into cacerts file.

        keytool -importcert -file ./mpdcertificates.pem -keystore ./cacerts
  2. The specified user settings file does not exist: C:\Users\hi\.m2\settings.xml

    By default, Maven does not create the settings.xml file under .m2 folder. To solve this problem, we can copy the settings.xml file from folder %MAVEN_HOME%\conf to .m2 folder.

  3. Set up the Maven Archetype Catalogs plugin

    • Go to File -> Settings -> Plugins -> Browse, then we have:

      Select File -> Invalidate Caches/Restart … item.

    • Then, go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven Archetype Catalogs.

      Find a archetype-catalog.xml file in C:\Users\hi.m2\repository folder.

Wrapping up

  • Understanding about structure folder in Maven project.
  • The important parameters in POM file such as parent, packaging, dependencies, properties, name, scope, …
  • How to add libraries into our project with Maven.
  • Necessary parameters for common libraries in Spring MVC.


POM file

JAR, WAR files

Project Dependecies

Setup maven in eclipse

Create empty maven project in eclipse