Unknown lifecycle phase on Maven

huangapple go评论72阅读模式
英文:

Unknown lifecycle phase on Maven

问题

我尝试在另一台笔记本电脑上重新运行我的Maven项目,文件完全相同。我使用以下命令进行编译:

mvn exec:java -Dexec.mainClass=id.tumbs.App

这在我进行项目的那台笔记本电脑上运行正常,但在另一台笔记本电脑上报错。错误代码如下:

[ERROR] 未知的生命周期阶段 ".mainClass=id.tumbs.App"。您必须指定一个有效的生命周期阶段或目标,格式为 <plugin-prefix>:<goal> 或 <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>。可用的生命周期阶段包括:validate、initialize、generate-sources、process-sources、generate-resources、process-resources、compile、process-classes、generate-test-sources、process-test-sources、generate-test-resources、process-test-resources、test-compile、process-test-classes、test、prepare-package、package、pre-integration-test、integration-test、post-integration-test、verify、install、deploy、pre-clean、clean、post-clean、pre-site、site、post-site、site-deploy。-> [帮助 1]
[ERROR]
[ERROR] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。
[ERROR] 使用 -X 开关重新运行 Maven 以启用完整调试日志记录。
[ERROR]
[ERROR] 有关错误和可能解决方案的更多信息,请阅读以下文章:
[ERROR] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

我已经尝试了错误链接提供的所有方法,但没有任何效果。请问有什么解决方案吗?


<details>
<summary>英文:</summary>

I tried to re-run my maven project in another laptop with the exact same file. I compiled it with this command:

    mvn exec:java -Dexec.mainClass=id.tumbs.App

This works on the laptop I was doing the project for, while throwing out an error on another laptop. The error code is

    [ERROR] Unknown lifecycle phase &quot;.mainClass=id.tumbs.App&quot;. You must specify a valid lifecycle phase or a goal in the 
format &lt;plugin-prefix&gt;:&lt;goal&gt; or &lt;plugin-group-id&gt;:&lt;plugin-artifact-id&gt;[:&lt;plugin-version&gt;]:&lt;goal&gt;. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -&gt; [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

I tried everything from what the error link told me and nothing work. Any solution, please?

</details>


# 答案1
**得分**: 22

尝试将主类用双引号括起来:

```bash
mvn exec:java -Dexec.mainClass="id.tumbs.App"

类似地,您可以使用 -Dexec.args="arg0 arg1" 来传递参数。

如果您在Windows上操作,需要为 exec.mainClass 和 exec.args 应用引号:

mvn exec:java -D"exec.mainClass"="id.tumbs.App"

如果您需要频繁执行此操作,您可以将参数添加到 pom.xml 文件中,如下所示:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
    <execution>
      <goals>
        <goal>java</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <mainClass>id.tumbs.App</mainClass>
    <arguments>
      <argument>arg0</argument>
      <argument>arg1</argument>
    </arguments>
  </configuration>
</plugin>

如果您想了解更多关于此事的详细信息,请查看 maven-exec-plugin

英文:

Try specifying your main class in double quotes:

mvn exec:java -Dexec.mainClass=&quot;id.tumbs.App&quot;

Similarly, you can use -Dexec.args=&quot;arg0 arg1&quot; to pass arguments.

If you're on Windows, you need to apply quotes for exec.mainClass and exec.args:

mvn exec:java -D&quot;exec.mainClass&quot;=&quot;id.tumbs.App&quot;

If you're doing this more frequently, you can add the parameters into the pom.xml like this:

&lt;plugin&gt;
  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
  &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
  &lt;version&gt;1.2.1&lt;/version&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;goals&gt;
        &lt;goal&gt;java&lt;/goal&gt;
      &lt;/goals&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
  &lt;configuration&gt;
    &lt;mainClass&gt;id.tumbs.App&lt;/mainClass&gt;
    &lt;arguments&gt;
      &lt;argument&gt;arg0&lt;/argument&gt;
      &lt;argument&gt;arg1&lt;/argument&gt;
    &lt;/arguments&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;

If you're interested in knowing more details about this, take a look at the maven-exec-plugin.

huangapple
  • 本文由 发表于 2020年10月11日 09:56:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64299956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定