YouTip LogoYouTip

Maven Deployment Automation

During the project development process, the deployment process includes the following steps: * Commit all project code to SVN or a code repository and tag it. * Download the complete source code from SVN. * Build the application. * Store the built WAR or EAR file to a common network location. * Retrieve the file from the network and deploy it to the production site. * Update documentation and update the application version number. ### Problem Description Usually, the development process mentioned above involves multiple teams. One team may be responsible for committing code, another team for building, and so on. Due to manual operations and a multi-team environment, any step is likely to 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 Automate the deployment by combining the following approaches: * Use Maven to build and release the project. * Use SubVersion, a source code repository, to manage source code. * Use a remote repository management software (Jfrog or Nexus) to manage project binary files. * * * ## Modifying 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: 4.0.0bus-core-apibus-core-api1.0-SNAPSHOTjarhttp://www.svn.comscm:svn:http://localhost:8080/svn/jrepo/trunk/ Frameworkscm:svn:${username}/${password}@localhost:8080: common_core_api:1101:codeCore-API-Java-ReleaseRelease repositoryhttp://localhost:8081/nexus/content/repositories/ Core-Api-Releaseorg.apache.maven.pluginsmaven-release-plugin2.0-beta-9falsedeploy- In the pom.xml file, some of the important element nodes we commonly use are listed in the following table: | Element Node | Description | | --- | --- | | SCM | Configures the SVN path from which Maven will retrieve the code. | | repository | The location for storing the built WAR, EAR, or JAR files, or other artifacts generated after a successful source code build. | | Plugin | Configures the maven-release-plugin to implement the automated deployment process. | * * * ## Maven Release Plugin Maven uses the maven-release-plugin to perform the following tasks. mvn release:clean Cleans the workspace to ensure the latest release process proceeds successfully. mvn release:rollback If the previous release process was unsuccessful, it rolls back the modified workspace code and configuration to ensure the release process succeeds. mvn release:prepare Performs multiple operations: * Checks for any uncommitted local modifications. * Ensures there are no snapshot dependencies. * Changes the application version information for release. * Updates the POM file to SVN. * Runs test cases. * Commits the modified POM file. * Tags the code in SVN. * Increases the version number and appends a snapshot for future releases. * Commits the modified POM file to SVN. mvn release:perform Switches the code to the previously tagged location, runs the Maven deploy goal to deploy the WAR file or build the corresponding structure to the repository. Open the command terminal, navigate to the C: > MVN >bus-core-api directory, and then execute the following mvn command. C:MVNbus-core-api>mvn release:prepare Maven starts building the entire project. After a successful build, you can run the following mvn command. C:MVNbus-core-api>mvn release:perform After a successful build, you can verify whether the uploaded JAR file in your repository is effective.
← Maven EclipseMaven Build Automation β†’