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:
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.
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="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>SampleWebApp</artifactId>
<packaging>war</packaging>
<version>1.0 </version>
<name>SampleWebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<scm>
<url>http://www.svn.com</url>
<connection>scm:svn:http://localhost:8080/svn/jrepo/trunk/Framework</connection>
<developerConnection>
scm:svn:test/test123@localhost:8080: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>
Have a closer look at the pom.xml and observe the below list of important tags used:
Tag Element | Description |
---|---|
scm | Configures the scm (in this cases SVN is used) of the project |
repositories | Storage location of the WAR/EAR/JAR file after the successful build |
plugin | maven-release-plugin to automate the process |
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:prepare - This tasks performs the below list of operations: