maven自动化构建项目_Maven构建自动化

maven自动化构建项目

Build automation is the process in which a project gets initiated with the build process whenever a change is made in the workspace and also to ensure that project is stable along with its dependent projects (if the project is used by any other projects).

生成自动化是一个过程,在该过程中,只要在工作区中进行了更改,项目就随构建过程而启动,并且还可以确保项目及其相关项目(如果该项目被任何其他项目使用)是稳定的。

This is very much essential in the software development life cycle as it is difficult to manage with the failed builds during the development phase. Hence, a process is required in order to ensure the health status of the build all the time and keep an eye on the same.

这在软件开发生命周期中非常重要,因为在开发阶段很难对失败的构建进行管理。 因此,需要一个过程来始终确保构建的健康状态并保持一致。

Consider the project JavaSamples in this scenario. Here, lot of programs varying across different oops concept will be written and tested. But, it is always difficult to test every class independently for the compilation issue since they are modularized under different set of packages.

在这种情况下,请考虑项目JavaSamples 。 在这里,将编写和测试跨不同oop概念的许多程序。 但是,始终很难针对编译问题单独测试每个类,因为它们是在不同的软件包集下进行模块化的。

In order to achieve this, maven provides a feature to automate the same. Consider, developers want to check the build stability after each check in done to the project. Also, consider that this JavaSamples project is a dependent project of another project called CoreJavaTutorials. Hence, it is mandatory to maintain a stable build of JavaSamples.

为了实现这一点,maven提供了自动执行此功能的功能。 考虑一下,开发人员希望在每次对项目完成后检查构建稳定性。 此外,考虑到这JavaSamples项目是另一个项目叫CoreJavaTutorials的相关项目。 因此,必须维护稳定的JavaSamples构建。

Below mentioned are the pom.xml files for two dependent projects.

下面提到的是两个相关项目的pom.xml文件。

CoreJavaTutorials Project

CoreJavaTutorials项目

<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>CoreJavaTutorials</groupId>
   <artifactId>CoreJavaTutorials </artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
   <dependencies>
      <dependency>
      <groupId>JavaSamples</groupId>
         <artifactId>JavaSamples</artifactId>
         <version>1.0-SNAPSHOT</version>
      </dependency>
   </dependencies>
</project>

JavaSamples Project:

JavaSamples项目:

<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>JavaSamples</groupId>
   <artifactId>JavaSamples</artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
</project>

Now consider that there are some changes made on the JavaSamples project. Developer need to update the pom.xml of the JavaSamples project by adding a post build goal on the same.

现在考虑对JavaSamples项目进行了一些更改。 开发人员需要通过在JavaSamples项目上添加后期构建目标来更新JavaSamples项目的pom.xml。

post build goal is nothing but, a goal which defines a specific set of tasks once the build is successful. For e.g. generating javadocs is a post build goal. We will study about generating Javadocs in coming tutorials.

构建后的目标不过是一个目标,一旦构建成功,该目标将定义一组特定的任务。 例如,生成javadocs是构建后的目标。 我们将在接下来的教程中研究有关生成Javadocs的信息。

<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>JavaSamples</groupId>
   <artifactId>JavaSamples</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   <build>
      <plugins>
         <plugin>
            <artifactId>maven-invoker-plugin</artifactId>
            <version>1.6</version>
            <executions>
               <execution>
                  <id>build</id>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>

使用Jenkins服务器进行构建自动化 (Build Automation using Jenkins Server)

Jenkins Server(click for complete Jenkins tutoriali>) is a continuous integration tool. Using Jenkins build can be automated, tested for the health status of the builds and also multiple builds can be managed. It is a handy tool which is easily available to download and very easy to set up.

Jenkins服务器 ( 单击以获取完整的Jenkins教程 i>)是一个持续集成工具。 可以自动使用Jenkins构建,对构建的运行状况进行测试,还可以管理多个构建。 这是一个方便的工具,可以轻松下载并设置。

设置Jenkins服务器 (Setting up Jenkins Server)

  • Download the latest Jenkins.war from following link : http://jenkins-ci.org/

    从以下链接下载最新的Jenkins.war: http : //jenkins-ci.org/

    Installing Jenkins Server
  • Deploy the Jenkins.war file in the local web server of our machine. E.g. Tomcat

    在我们机器的本地Web服务器上部署Jenkins.war文件。 例如Tomcat

  • Start the server and open the browser and hit the URL http://localhost:8080/jenkins

    启动服务器并打开浏览器,然后单击URL http:// localhost:8080 / jenkins

    Setting up Jenkins Server and Automating Maven Build

创建一个新作业并部署构建 (Creating a new Job and Deploying the Build)

Click on the Create new jobs link, shown in picture above, to configure a project for build automation. Enter the details of the project as shown below and click OK. You must enter the Name and select the radio button for Maven Project.

单击上图所示的“ 创建新作业”链接,以配置用于构建自动化的项目。 输入项目的详细信息,如下所示,然后单击“ 确定” 。 您必须输入名称并为Maven Project选择单选按钮。

Setting up Jenkins Server and Automating Maven Build

In the next page, fill all the required details like - Description, Path of the project's pom.xml and other details and click save. Please check the below picture for help. Fill all the information and click on SAVE

在下一页中,填写所有必需的详细信息,例如-说明,项目的pom.xml的路径以及其他详细信息,然后单击“保存”。 请检查以下图片以获取帮助。 填写所有信息,然后单击“ 保存”

Setting up Jenkins Server and Automating Maven Build
Setting up Jenkins Server and Automating Maven Build
Setting up Jenkins Server and Automating Maven Build

A Project/Job is now created in Jenkins. As shown below :

现在在詹金斯创建了一个项目/工作。 如下所示 :

Setting up Jenkins Server and Automating Maven Build

Click on the Build now option as shown above. This will read the pom.xml and pull out the latest code and executes a build process and generates the jar/war file accordingly.

单击上面所示的“立即构建”选项。 这将读取pom.xml并提取最新代码,并执行构建过程并相应地生成jar / war文件。

Setting up Jenkins Server and Automating Maven Build

Click on the build number link and it opens up the build details. Click on the Console Output to see the logs of the build.

单击内部版本号链接,它会打开内部版本详细信息。 单击控制台输出以查看生成的日志。

Build Automation in Maven using Jenkins Server

Check the logs and see your project building successfully.

检查日志并查看您的项目构建成功。

Build Automation in Maven using Jenkins Server
Build Automation in Maven using Jenkins Server

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

maven自动化构建项目

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值