Signup/Sign In

Maven Deployment Automation

In the previous tutorial, we learnt about creating a simple web project by using the maven archetype and also understood how maven organizes the project structure based on the selected archetype. In order to test the web application created by the maven, we followed the manual way of deploying the application (war file) into the web server and tested the same.

In a real time project, a typical deployment process involves the below list of activities:

  • Checking in the code to the repository.
  • Download the source code from the repository.
  • Compile and build the application and generate jar/war from the same.
  • Locate the generated war/jar in a common shared network location.
  • Download the jar/war file and deploy to the target server
  • Also, documentation and versioning details of the application needs to be update.

Since, any real time project will always involve multiple teams working for the above set of activities, sometimes a particular step may be missed out and which would result in the failure of the build and deployment process.

Also, it is observed practically that manually handling the above steps will be error prone most of the times. To overcome this issue, the deployment process should be automated so there will not be any intervention and also the deployment is successful.

How to Automate the Deployment Process?

Basically, to automate the build & release process in maven, release plugin of the maven will be used. Open the pom.xml of the project and update as shown below:

<project xmlns="" xmlns:xsi=""
  <version>1.0 </version>
  <name>SampleWebApp Maven Webapp</name>
        <name>Release repository</name>


Have a closer look at the pom.xml and observe the below list of important tags used:

Tag ElementDescription
scmConfigures the scm (in this cases SVN is used) of the project
repositoriesStorage location of the WAR/EAR/JAR file after the successful build
pluginmaven-release-plugin to automate the process

How does maven-release-plugin works?

With the updated pom.xml, we all set to automate the deployment process of a project in maven. But, before to conclude this, it is vital to understand what actually happens in the background that makes the deployment process as automated.

When maven invokes the plugin maven-release-plugin, the below tasks are executed accordingly:

  • mvn release:clean - cleans up the workspace for the last build and sets up for a fresh build.
  • mvn release:rollback - if the last process was unsuccessful, it reverts/rollback the workspace.
  • mvn release:prepare - This tasks performs the below list of operations:

    • Checks out for any uncommitted files in the local workspace.
    • Checks and ensures for no SNAPSHOT dependencies.
    • Prepares the Release version.
    • Updates the pom to SCM (SVN/Git/Mercurial/CVS)
    • Executes the test cases.
    • Performs the final commit to the SCM.
    • Tags the code.
    • Increments the version no. and adds the SNAPSHOT as part of the future releases.
  • mvn release:perform - checks out the code from the repository and runs the maven goal to build and deploy the artifacts to the repository.