Spring Boot之mvnw的启动错误Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain

来源:互联网 发布:腾讯云域名dns是多少 编辑:程序博客网 时间:2024/06/03 13:20

引言: 偶尔在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 -versionApache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00)Maven home: /opt/mavenJava version: 1.8.0_91, vendor: Oracle CorporationJava home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "3.10.0-327.3.1.el7.x86_64", arch: "amd64", family: "unix"


0 0
原创粉丝点击