将项目构建成maven项目_构建并测试您的第一个Maven项目

将项目构建成maven项目

构建并测试您的第一个Maven项目 (Build and Test your First Maven Project)

In the previous tutorial, we have seen how to create sample maven project using maven archetype and understood how the folder structure is organized. Now, we will see how to build a project and test the code written.

在上一个教程中,我们已经了解了如何使用Maven原型创建示例Maven项目,并了解了文件夹结构的组织方式。 现在,我们将看到如何构建项目并测试编写的代码。

建立一个Maven项目 (Building a Maven Project)

Once the coding is completed in the project, the project needs to be compiled, built and make it to be ready for the deployment.

一旦项目中的编码完成,就需要对项目进行编译,构建并使其准备好进行部署。

To achieve this, Open the Command Prompt and navigate to the root project folder where it consists of the pom.xml file. E.g. D:\Java\workspace\JavaSamples. Now, type the command mvn package and press enter. This command will invoke the maven package phase.

为此,请打开命令提示符,然后导航到包含pom.xml文件的根项目文件夹。 例如D:\ Java \ workspace \ JavaSamples。 现在,键入命令mvn package并按Enter。 此命令将调用maven软件包阶段。

As explained here, whenever a maven phase is invoked, it executes in a sequence up to the invoked phase. Hence, in this case the phases above package – validate, compile and test phases will be executed.

如此处所述,无论何时调用maven阶段,它都会按顺序执行,直到调用阶段为止。 因此,在这种情况下,将执行以上程序包的各个阶段– 验证编译测试阶段。

将项目构建成maven项目_构建并测试您的第一个Maven项目

将项目构建成maven项目_构建并测试您的第一个Maven项目

When mvn package command is run, maven will validates and compile the source code, execute the junit test cases and packs/bundles it as per the instructions given in the tag <packaging> in the pom.xml file. If the packaging is specified as jar, then a jar with the package will be created.

当运行mvn package命令时,maven将验证并编译源代码,执行junit测试用例,并按照pom.xml文件中的<packaging>标记中给出的说明对其进行打包/捆绑。 如果将包装指定为jar ,则将创建带有包装的jar。

将项目构建成maven项目_构建并测试您的第一个Maven项目

  • D:\Java\workspace\JavaSamples\target. D:\ Java \ workspace \ JavaSamples \ target
  • D:\Java\workspace\JavaSamples\target\surefire-reportsD:\ Java \ workspace \ JavaSamples \ target \ surefire-reports中


To run the App.test java, open the command prompt and navigate to the folder D:\Java\workspace\JavaSamples\target\classes and enter the command java com.java.samples.App

要运行App.test java,请打开命令提示符并导航到文件夹D:\ Java \ workspace \ JavaSamples \ target \ classes并输入命令java com.java.samples.App

将项目构建成maven项目_构建并测试您的第一个Maven项目



To run the test classes (junits), open the command prompt and from the root folder of the project, execute the command mvn test

要运行测试类(junits),请打开命令提示符,然后从项目的根文件夹中执行命令mvn test

将项目构建成maven项目_构建并测试您的第一个Maven项目

将项目构建成maven项目_构建并测试您的第一个Maven项目

翻译自: https://www.studytonight.com/maven/build-and-test-maven-project

将项目构建成maven项目