maven 工程自动化部署_Maven部署自动化

maven 工程自动化部署

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.

在上一教程中,我们学习了如何使用maven原型创建一个简单的Web项目,并且还了解了maven如何根据所选的原型组织项目结构。 为了测试由Maven创建的Web应用程序,我们遵循了将应用程序(war文件)部署到Web服务器中的手动方法,并对其进行了测试。

In a real time project, a typical deployment process involves the below list of activities:

在实时项目中,典型的部署过程涉及以下活动列表:

  • Checking in the code to the repository.

    将代码检入到存储库中。

  • Download the source code from the repository.

    从资源库下载源代码。

  • Compile and build the application and generate jar/war from the same.

    编译并构建应用程序,并从中生成jar / war。

  • Locate the generated war/jar in a common shared network location.

    在公共共享网络位置找到生成的war / jar。

  • Download the jar/war file and deploy to the target server

    下载jar / war文件并部署到目标服务器

  • Also, documentation and versioning details of the application needs to be update.

    另外,需要更新该应用程序的文档和版本详细信息。

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.

而且,实际上观察到,在大多数情况下,手动处理上述步骤将容易出错。 为了克服此问题,应该使部署过程自动化,这样就不会有任何干预,并且部署也会成功。

如何自动化部署过程? (How to Automate the Deployment Process?)

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:

基本上,为了使maven中的构建和发布过程自动化,将使用maven的release插件。 打开项目的pom.xml并更新,如下所示:

<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:

仔细查看pom.xml并观察以下使用的重要标记列表:

Tag ElementDescription
scmConfigures the scm (in this cases SVN is used) of the project
repositoriesStorage location of the WAR/EAR/JAR file after the successful build
pluginmaven-release-plugin to automate the process
标签元素 描述
平方厘米 配置项目的scm(在这种情况下使用SVN)
仓库 成功构建后,WAR / EAR / JAR文件的存储位置
插入 maven-release-plugin自动执行该过程

maven-release-plugin如何工作? (How does 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.

使用更新的pom.xml,我们所有人都可以设置为自动化maven中项目的部署过程。 但是,在得出结论之前,至关重要的是要了解在后台使部署过程实现自动化的实际情况。

When maven invokes the plugin maven-release-plugin, the below tasks are executed accordingly:

当maven调用插件maven-release-plugin时,以下任务将相应执行:

  • mvn release:clean - cleans up the workspace for the last build and sets up for a fresh build.

    mvn release: clean-清理上一次构建的工作空间并设置为新的构建。

  • mvn release:rollback - if the last process was unsuccessful, it reverts/rollback the workspace.

    mvn release:rollback-如果最后一个过程失败,它将还原/回滚工作空间。

  • mvn release:prepare - This tasks performs the below list of operations:

    mvn release:prepare-此任务执行以下操作列表:

    • Checks out for any uncommitted files in the local workspace.
    • Checks and ensures for no SNAPSHOT dependencies.
    • Prepares the Release version.
    • Updates the pom to SCM (SVN/Git/Mercurial/CVS)
    • Executes the test cases.
    • Performs the final commit to the SCM.
    • Tags the code.
    • Increments the version no. and adds the SNAPSHOT as part of the future releases.
  • mvn release:perform - checks out the code from the repository and runs the maven goal to build and deploy the artifacts to the repository.

    mvn release:perform-从存储库中检出代码,并运行maven目标以构建工件并将其部署到存储库。

翻译自: https://www.studytonight.com/maven/maven-deployment-automation

maven 工程自动化部署

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值