提问人:Thomas Murphy 提问时间:2/14/2018 更新时间:4/19/2021 访问量:8407
找不到 MavenWrapperMain 类,但包含在目录中的 .m2 中
could not find MavenWrapperMain class, but is contained within .m2 in the directory
问:
所以对我来说,这是一个新的......我正在使用一个 Spring Boot 指南,并获取
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
运行时出错
./mvnw spring-boot:run
(或任何 Maven Wrapper 命令)
也就是说,我看到罐子在我期望的地方。wrapper
.mvn
还有其他人打过这个吗?似乎这一定是系统级的问题,因为我过去没有遇到过这个问题。
这是我运行此命令的存储库:https://github.com/spring-guides/gs-scheduling-tasks.git
答:
初始项目是一个空项目,因此当您在此文件夹中运行时,消息很清楚,并告诉您项目中没有主类可以作为 Spring Boot 应用程序运行。./mvnw spring-boot:run
如果在 complete 文件夹中运行该命令,则运行的项目具有本教程的所有逻辑。
如果你在根文件夹中cd,然后从complete或initial文件夹内运行mvnw,你会收到该消息,因为它就像你CD到一个完全不相关的文件夹,如/test/project(你可以尝试一下)。
mvnw 所做的是尝试查找并运行一个 .pom 文件,其中除了 complete 和 initial 之外的所有文件夹中都不存在。
评论
/Code/Java:Spring/gs-rest-service/complete
尝试从 .m2 目录中删除它并再次重建,我曾经遇到过类似的问题,只有在我从 .m2 中删除 jar 并再次重建它时才解决
您必须添加配置
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html
它显示在完整的目录中,但没有任何类或带注释的类(作为选项而不是配置部分)
刚刚在 Windows 上以“完成”完成
[INFO] Installing D:\projects\edu_test\gs-scheduling-tasks\complete\pom.xml to C:\Users\alex\.m2\repository\org\springframework\gs-scheduling-tasks\0.1.0\gs-scheduling-tasks-0.1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
我终于想通了,所以为后人发帖:
如果 Maven 下载由于某种原因而损坏,并且由于连接丢失或其他原因而未成功下载,则会引发此错误。
缓解措施是(在 Spring Boot 应用程序文件夹中):
rm -rf .mvn
./mvnw spring-boot:run
评论
[ERROR] No plugin found for prefix 'spring-boot' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local ([home]\.m2\repository), central (https://repo.maven.apache.org/maven2)]
初始
文件夹启动:我有这个错误:[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.10.RELEASE:run (default-cli) on project gs-scheduling-tasks: Unable to find a suitable main class, please add a 'mainClass' property
完整
文件夹启动:Spring Boot 应用程序启动,每 5 秒打印一次当前时间。mvn -N io.takari:maven:wrapper
complete