英文:
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 ".mainClass=id.tumbs.App". You must specify a valid lifecycle phase or a goal in the
format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. 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. -> [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="id.tumbs.App"
Similarly, you can use -Dexec.args="arg0 arg1"
to pass arguments.
If you're on Windows, you need to apply quotes for exec.mainClass and exec.args:
mvn exec:java -D"exec.mainClass"="id.tumbs.App"
If you're doing this more frequently, you can add the parameters into the pom.xml like this:
<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>
If you're interested in knowing more details about this, take a look at the maven-exec-plugin.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论