使用 Maven 和 Eclipse 运行 Tomcat - 未知生命周期阶段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13251669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Tomcat with Maven and Eclipse - Unknown lifecycle phase
提问by Antony
I am using Eclipse Helios,Tomcat Server 7. I have build my project using Maven. When I try to build my project, I get the below error in Eclipse.
我正在使用 Eclipse Helios、Tomcat Server 7。我使用 Maven 构建了我的项目。当我尝试构建我的项目时,我在 Eclipse 中收到以下错误。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building encore Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.095s
[INFO] Finished at: Tue Nov 06 18:17:55 IST 2012
[INFO] Final Memory: 2M/36M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "build". 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
Please let me know what is wrong in my code and kindly point to right directions. I need to figure it out ASAP.
请让我知道我的代码有什么问题,并请指出正确的方向。我需要尽快弄清楚。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.encore</groupId>
<artifactId>encore</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>encore Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</dependency>
</dependencies>
<build>
<finalName>encore</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>2.9</version>
<configuration>
<server>mytomcatserver</server>
<path>/encore</path>
<url>http://localhost:8080</url>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is my pom.xml. I am trying to Run my application as Run as-> mvn build from eclipse.
这是我的 pom.xml。我正在尝试将我的应用程序作为 Run as-> mvn build from eclipse 运行。
回答by Duncan Jones
It sounds like you've accidentally set the wrong goal when trying to build from Eclipse. Edit your Maven "Run as.." settings like so:
听起来您在尝试从 Eclipse 构建时不小心设置了错误的目标。像这样编辑你的 Maven “Run as..” 设置:
Note the clean install
which will run the Maven commands to clean your build and do a full build and install into the local repository.
请注意clean install
,它将运行 Maven 命令来清理您的构建并执行完整构建并安装到本地存储库中。
回答by Aaron Digulla
Try mvn install
instead of mvn build
. build
is not a valid option for Maven. You can find a list of valid options in the error message above.
尝试mvn install
代替mvn build
. build
不是 Maven 的有效选项。您可以在上面的错误消息中找到有效选项的列表。
If you just want to compile the sources, try mvn compile
but that will usually produce an incorrect result when you have more than one pom.xml
file in your project.
如果您只想编译源代码,请尝试,mvn compile
但是当您的项目中有多个pom.xml
文件时,这通常会产生不正确的结果。
回答by user2798976
You should build : install , not build : mvn install ,not start with mvn ...
您应该构建:安装,而不是构建:mvn install,而不是从 mvn 开始...
回答by erhanasikoglu
All ides ( Eclipse, Intellij etc.) have some problems with maven build, instead of using bundled maven component, use command-line maven. In command line ( windows or linux console does not matter.) mvn clean, then mvn install will fix your problem. Command line usage can be change your view point of maven.
所有 ide(Eclipse、Intellij 等)在 maven 构建方面都有一些问题,而不是使用捆绑的 maven 组件,而是使用命令行 maven。在命令行(Windows 或 linux 控制台无关紧要。) mvn clean,然后 mvn install 将解决您的问题。命令行的使用可以改变你对 maven 的看法。
回答by user3772423
It is most probable you set incorrect goals in the configuration when you ran "run as" "Maven build" and now can't change it.
当您运行“作为”“Maven 构建”运行时,很可能您在配置中设置了不正确的目标,现在无法更改它。
Right click on the project -> run as -> Run configurations.
右键单击项目 -> 运行方式 -> 运行配置。
A picture to illustrate: https://i.stack.imgur.com/Ry65K.png
一张图来说明:https: //i.stack.imgur.com/Ry65K.png
This will bring back up the window you first had on your first build and you can then follow the instructions of the more experienced contributors above.
这将带回您在第一次构建时最初使用的窗口,然后您可以按照上述更有经验的贡献者的说明进行操作。
Hope this helps.
希望这可以帮助。
回答by Mani P
I also had the same problem, uninstall the GIT bash and install again. This will resolve EnvVar issue is any.
我也有同样的问题,卸载 GIT bash 并重新安装。这将解决 EnvVar 问题。
If still not solved, please check with your commands. Copy and paste your commands from notepad and this should work
如果仍未解决,请检查您的命令。从记事本复制并粘贴您的命令,这应该可以工作
回答by vijay m p
Error: org.apache.maven.lifecycle.LifecyclePhaseNotFoundExceptionFor more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
错误:org.apache.maven.lifecycle。LifecyclePhaseNotFoundException有关错误和可能的解决方案的更多信息,请阅读以下文章: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ LifecyclePhaseNotFoundException
Solution: Unknown lifecycle phase or wrong goal example:First I am using "clean package tea-container-test:tomcat-test -P "XXX" -e" as goal?, then I changed a goal as "test -P XXX" , then It works perfectly,so Please check , your goal is right or wrong. "Creates a new exception to indicate that the specified lifecycle phase is not defined by any known lifecycle".
解决方案:未知的生命周期阶段或错误的目标示例:首先我使用“clean package tea-container-test:tomcat-test -P "XXX" -e”作为目标?,然后我将目标更改为“test -P XXX” ,然后它完美地工作,所以请检查,你的目标是对还是错。“创建一个新异常以指示指定的生命周期阶段未由任何已知生命周期定义”。