轉載自:https://blog.csdn.net/blueheart20/article/details/52185440
引言: 偶爾在Spring Boot的使用過程中,你會碰到這樣的錯誤,於是滿世界的找問題,有時候其實你想錯了,不是maven的錯,而是spring boot本身的某些設置才會有,本文將解決這個錯誤。
1. 錯誤信息
在下載了一個spring boot項目之后,將要運行啟動項目之時,發現啟動不了,報出如下錯誤信息:
[root@flybird WXDemo]# ./mvnw
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
2. 分析過程
首先是按照mvn設置本身的問題方向來分析,M2_HOME, PATH等各種環境變量一通查,沒有發現問題。於是切換了maven的版本,還是沒有能夠解決問題,於是網絡一通四處搜索,但是都是說,應該是環境變量配錯導致的問題,其實,我總覺得不應該是這個原因,因為mvn可以正常工作。
於是換個思路,是不是spring boot的某些內容帶給了maven的設置修改,順着這個思路查,萬能的google幫忙我們找到了答案,缺少了某些配置信息和jar包。
3. 解決問題
網上的指令說使用: mvn –N io.takari:maven:wrapper
mvn –N io.takari:maven:wrapper
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WXDemo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping WXDemo
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.909 s
[INFO] Finished at: 2016-08-11T18:43:48+08:00
[INFO] Final Memory: 8M/29M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "–N". 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
結果分析,-N這個參數不支持,好吧,那就去掉好了。
執行新的命令: mvn io.takari:maven:wrapper
[root@test WXDemo]# mvn io.takari:maven:wrapper
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WXDemo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven:0.3.3:wrapper (default-cli) @ meal ---
[INFO]
[INFO] The Maven Wrapper has been successfully setup for your project.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.693 s
[INFO] Finished at: 2016-08-11T18:45:51+08:00
[INFO] Final Memory: 9M/29M
[INFO] ------------------------------------------------------------------------
4. 驗證mvnw命令
執行指令: ./mvnw
[root@test WXDemo]# ./mvnw
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.812 s
[INFO] Finished at: 2016-08-11T18:46:33+08:00
[INFO] Final Memory: 8M/29M
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this 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/NoGoalSpecifiedException
可以正常執行這個猥瑣的命令了。
5. mvn的版本
在官方給出的文檔中的-N參數不支持的問題,可以歸結為mvn版本之間的變化以及遷移。此測試中出現的mvn版本信息如下:
[root@flybird WXMeal]# mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00)
Maven home: /opt/maven
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.3.1.el7.x86_64", arch: "amd64", family: "unix"
————————————————
版權聲明:本文為CSDN博主「bladestone」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/blueheart20/article/details/52185440