Maven - SPLessons

Maven Deployment Automation

Chapter 16

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Deployment Automation

Maven Deployment Automation

shape Introduction

In the previous tutorial, how to create a web application manually is shown. Maven Deployment Automation chapter explains about the real-time projects build & deployment, automation process and functions of Maven release plug-in.

shape Description

In real-time projects, project deployment is typical and involves the following steps:

All the above steps will be followed by any team while working on real time projects. If any of the above steps are not followed, it results in project build and deployment failures. So, to complete the project successfully without any errors, the errors have to be handled automatically to prevent the application intervention. In Maven, Deployment Automation is the process that can automate the deployment process.

shape Conceptual
figure

Deployment Process-Automation

shape Description

The automation of Maven build and deployment processes will be carried out by release plug-in. Open the pom.xml file of previous application-WebApplication and rewrite the code as shown below.

<project 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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sample.webproject</groupId>
  <artifactId>WebApplication</artifactId>
  <packaging>war</packaging>
  <version>1.0 </version>
  <name>WebApplication Maven Webapp</name>
  <url>http://maven.apache.org</url>
   
  <scm>
     <url>http://www.svn.com</url>
     <connection>scm:svn:http://localhost:8011/svn/jrepo/trunk/Framework</connection>
     <developerConnection>
         scm:svn:test/test123@localhost:8011:common_core_api:1101:code
     </developerConnection>
   </scm>
    
   <distributionManagement>
      <repository>
         <id>Sample-Web-App-Release</id>
         <name>Release repository</name>
         <url>
            http://localhost:8082/nexus/content/repositories/Sample-Web-App-Release
         </url>
      </repository>
   </distributionManagement>
    
    <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.0-beta-9</version>
            <configuration>
               <useReleaseProfile>false</useReleaseProfile>
               <goals>deploy</goals>
               <scmCommentPrefix>[Sample-Web-App-checkin]</scmCommentPrefix>
            </configuration>
         </plugin>
      </plugins>
   </build>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
   
</project>

The above XML file consists of 3 main tags.

Element Description
SCM SCM configures the location of SVN where the source code is placed.
Repository The location of JAR/WAR files after the project build is successful.
Plug-in Release plugin used for deployment automation.

Maven release plug-in

shape Functions

Maven release plug-in will perform the following tasks when invoked by projects.

So, to automate the present project, run the following command to build the project.
mvn release:prepare

After the build is successful, enter the below command to upload the WAR file into the repository.
mvn release:perform

Summary

shape Key Points

  • Maven Deployment Automation removes the errors while generating the build for a project.
  • SCM, repository and plug-in elements must be included in the pom.xml file.
  • Clean, rollback, prepare and perform are the four operations performed by the release plug-in.

shape Programming
Tips

Make sure to have the same port number both in the server and pom file while deploying.