首页 > 解决方案 > Maven 项目在 Eclipse 和命令行中失败

问题描述

我正在尝试在 eclipse 中运行一个简单的 maven 项目。当我以“Maven Clean”运行时给我消息“BUILD SUCCESS”但是当我以“Maven Test”运行我的测试时,它再次显示“BUILD SUCCESS”但不打印“你好世界”来自 Systemprintln。下面是我的课。

import org.testng.annotations.Test;
public class TestHellowWorld {

    public void testHellowWorld(){
        @Test
        System.out.println("hello world");
}

}
I am getting following message:
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld_raghav 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloworld_raghav ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloworld_raghav ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloworld_raghav ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloworld_raghav ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ helloworld_raghav ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.536 s
[INFO] Finished at: 2020-04-17T23:13:06-04:00
[INFO] Final Memory: 9M/245M
Now if I try to run this project through command line,build failed with the following message;

C:\Users\tarishah\workspace\helloworld_tarishah>mvn -clean
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< helloworld_raghav:helloworld_raghav >-----------------
[INFO] Building helloworld_raghav 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.164 s
[INFO] Finished at: 2020-04-17T23:08:11-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "lean". 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

标签: maven

解决方案


Maven 说Unknown lifecycle phase "lean"这意味着您没有运行mvn test(正如您在问题中指出的那样),而是类似mvn leanor mvn lean test


推荐阅读