Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Apache Maven automated deployment


May 26, 2021 Maven


Table of contents


Maven - Automated deployment

In general, in an engineering development process, the process of deploying at once requires the following steps:

  • Join the code under each sub-project into the SVN or source code library and mark it.
  • Download the full source code from SVN.
  • Build your application.
  • Save the build result as a WAR or EAR type file and store it in a common designated network location.
  • Get the file from the network and deploy it to the product line.
  • Update the document date and version number of the application.

Statement of the problem

Typically, there will be many different people involved in the above deployment process. O ne team can be responsible for the code's joining, the other can be responsible for building, and so on. A ny of these steps may not have been performed for human reasons. For example, older versions are not updated on network machines, and the team responsible for deployment has once again deployed older versions.

Solution

Automate deployment by combining:

  • Maven build and publish projects,
  • SubVersion, the source code library used to manage the source code,
  • The Remote Warehouse Management Tool (Jfrog/Nexus) manages the binary files of the project.

Update the POM of the .xml

We'll use the plug-ins published by Maven to create an automated publishing process:

For example: the POM of the bus-core-api .xml 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 pom .xml, the important elements we often use are the following table:

Elements Describe
Scm Configure the path to the SVN from which Maven will remove the code.
Warehouse The path to storage of the successfully built WAR/EAR/JAR or other build results.
Plug - ins maven-release-plugin is used to automate the deployment process.

Maven Release plug-in

Maven uses maven-release-plugin to perform the following useful tasks:

mvn release:clean

Clean up the workspace to ensure that the latest release process is successful.

mvn release:rollback

Rolling back the modified workspace code and configuration ensures that the release process is successful.

mvn release:prepare

Do the following several times:

  • Check locally for changes that have not yet been committed
  • Make sure that there are no snapshot dependencies
  • Change the version information of the application to publish
  • Update the POM file to the SVN
  • Run the test case
  • Submit the modified POM file
  • Mark the code on the SVN
  • Add version numbers and additional snapshots for future releases
  • Submit the modified POM file to SVN.
mvn release:perform

Switch the code to a previously marked place, run the Maven deployment target to deploy the WAR file, or build the appropriate structure into the warehouse.

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

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

Maven began to build the entire project. Once the build is complete, you can run the following mvn command.

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

Once the build is successful, you can verify that the JAR file uploaded under your repository is in effect.