Easy Tutorial
❮ Maven Build Life Cycle Maven Web Application ❯

Maven Automated Deployment

During the project development process, the deployment involves the following steps:

Problem Description

Typically, the development process mentioned above involves multiple teams. One team may be responsible for submitting code, another for building, and so on. Due to human operations and the multi-team environment, any step can go wrong. For example, an older version might not be updated on the network machine, and then the deployment team redeploys an earlier build version.

Solution

Automated deployment can be achieved by integrating the following solutions:


Modify the Project's pom.xml

We will use Maven's release plugin to create an automated release process.

For example, the pom.xml file for the bus-core-api project is as follows:

<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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>bus-core-api</groupId>
   <artifactId>bus-core-api</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging> 
   <scm>
      <url>http://www.svn.com</url>
      <connection>scm:svn:http://localhost:8080/svn/jrepo/trunk/
      Framework</connection>
      <developerConnection>scm:svn:${username}/${password}@localhost:8080:
      common_core_api:1101:code</developerConnection>
   </scm>
   <distributionManagement>
      <repository>
         <id>Core-API-Java-Release</id>
         <name>Release repository</name>
         <url>http://localhost:8081/nexus/content/repositories/
         Core-Api-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>[bus-core-api-release-checkin]-<
               /scmCommentPrefix>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

In the pom.xml file, some commonly used important elements are shown in the table below:

| Element Node | Description | | SCM | Configure the SVN path, from which Maven will fetch the code. | | repository | The location where the built WAR or EAR or JAR files are stored, or where other source code builds successfully generate artifacts. | | Plugin | Configure the maven-release-plugin to automate the deployment process. |


Maven Release Plugin

Maven uses the maven-release-plugin to accomplish the following tasks.

mvn release:clean

Cleans the workspace to ensure the latest release process is successful.

mvn release:rollback

Rolls back the workspace code and configuration in case the previous release process was unsuccessful, ensuring the release process can proceed successfully.

mvn release:prepare

Performs multiple actions:

Switches the code to the previously tagged location, runs the Maven deployment goal to deploy the WAR file or build the corresponding structure into the repository.

Open the command terminal, navigate to the C:\ > MVN >bus-core-api directory, and then execute the following mvn command.

C:\MVN\bus-core-api>mvn release:prepare

Maven starts building the entire project. After a successful build, you can run the following mvn command.

C:\MVN\bus-core-api>mvn release:perform

After a successful build, you can verify if the JAR file uploaded to your repository is effective.

❮ Maven Build Life Cycle Maven Web Application ❯