Maven:生命周期阶段运行程序? [英] Maven: lifecycle phase to run a program?

查看:124
本文介绍了Maven:生命周期阶段运行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Maven编译和测试程序

I can use Maven to compile and test a program

mvn compile
mvn test

是否存在生命周期命令来简单地运行程序,或生成将运行该程序的脚本?

Is there a lifecycle command to simply run the program, or generate a script which will run the program?

推荐答案

如果您提出此问题,则意味着您不清楚

If you are asking this question, it means it's unclear to you what the Maven lifecycle really is.

没有生命周期 command ,只有构建生命周期,它由不同的阶段组成.

There is no lifecycle command, only a build lifecycle, which is made up of different phases.

因此要明确一点:存在一个构建生命周期,该生命周期由各个阶段组成,这些阶段由插件目标组成.

So to make it clear: there is a build lifecycle, which is made up of phases, which are made up of plugin goals.

当您使用调用Maven时

When you are invoking Maven with

mvn compile

您正在调用构建阶段.在Maven中,有预定义的有序阶段列表.当您调用一个阶段时,它之前的所有阶段也会被调用.调用阶段意味着您正在调用绑定到该阶段的所有插件.对于compile情况,这意味着它将默认调用绑定到compile阶段的maven-compiler-plugin.

You are invoking a build phase. In Maven, there is a list of predefined ordered phases. When you invoke a phase, all of the phase before it are also invoked. Invoking a phase means that you are invoking all of the plugins that are bound to this phase. For the compile case, this means it will, among others, invoke the maven-compiler-plugin wich is bound to the compile phase by default.

所以要严格回答您的问题:不,没有生命周期命令可以做到这一点.

So to answer your question strictly: no, there is no lifecycle command to do that.

但是,您可以在POM中配置一个将绑定到特定阶段的插件,然后调用该阶段.为此,您可以参考介绍exec-maven-plugin的@manouti答案.

However, you can configure a plugin in your POM, which will be bound to a certain phase, and invoke that phase. For that, you can refer to @manouti's answer which introduces the exec-maven-plugin.

这篇关于Maven:生命周期阶段运行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆