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

将项目构建成maven项目

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阶段,它都会按顺序执行,直到调用阶段为止。 因此,在这种情况下,将执行以上程序包的各个阶段– 验证编译测试阶段。

Build and Test Maven Project
Build and Test Maven Project

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。

Build and Test Maven Project
  • The packaged jar file will be available under the target directory of the project. i.e. D:\Java\workspace\JavaSamples\target.

    打包的jar文件将在项目的目标目录下可用。 即D:\ Java \ workspace \ JavaSamples \ target

  • All the test reports (junit tests details) are available in the folder D:\Java\workspace\JavaSamples\target\surefire-reports

    所有测试报告(junit测试详细信息)都位于文件夹D:\ 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

Build and Test Maven Project

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

Build and Test Maven Project
Build and Test Maven Project

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

将项目构建成maven项目

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值