Build Project Maven

Build Project Maven

Maven is a build tool which used primarily in Java project. Because it’s java based tool so before using it you will have to installed JDK on your computer then download and install maven using this tutorial

  • Once installation is complete open command prompt type below command:

Build Project Maven

  • Create sample maven web project and below is sample project structure of maven web project:

Build Project Maven

  • As you see default directory structure of the project. Its main file that is called pom.xml is a core configuration of project where all information about project build is stored and it has details about project the way you want. If you are working on big project you will see pom.xml file huge can be difficult to understand but its not mandatory is to understand all of its component to use it effectively. Basic structure of pom.xml:

Run maven build: There are various phases are involved to build project in maven:

  • validate: It validates project is correct and check if all necessary information are available]
  • compile: Compile source code
  • test: Test compiled source code using unit testing framework. These tests should not require the code be packaged or deployed
  • package: Package the project in its distributed format
  • integration-test: Process and deploy package into an environment where we can run integration tests
  • verify: Verify packages if they are valid and meets criteria
  • install: Install project into local repository
  • deploy:Release on the environment and copies final package to remote repository

And apart form this there are two other maven life-cycle steps you can use:

  • clean: This cleans up all the build artifacts created before
  • site: This generates site documentation of the project

Please note: Executing any build phases maven executes its previous phases. For example if you execute install command it will all its previous command in order: validate –> compile — > test –> package –> integration-test –> verify –> install

  • Before running build it is good practice to execute clean command to clean out any previous build artifacts as below:

Build Project Maven

  • Now as you saw above for demo we have created web project it means packaging type is WAR. To package this project to WAR archive and ready to make it deployable on the server execute package command as below this will create WAR file inside target directory:


  • To verify if WAR file is created or not refresh target directory you should see new WAR file:


  • For more details visit maven official site here

download  Download Project:  MavenTestProject

Leave a Reply

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

I am not Robot *