Java 无法找到或加载主类 org.apache.maven.wrapper.MavenWrapperMain

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50104172/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:26:14  来源:igfitidea点击:

Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain

javaspringmavenspring-boottravis-ci

提问by Yang Luo

I have a spring boot project here: https://github.com/jcasbin/jcasbin-springboot-plugin. I encountered the following error in Travis CI:

我在这里有一个 spring boot 项目:https: //github.com/jcasbin/jcasbin-springboot-plugin。我在 Travis CI 中遇到以下错误

shell
3.43s$ ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
/home/travis/build/jcasbin/jcasbin-springboot-plugin
Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
The command "eval ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V " failed. Retrying, 2 of 3.

It seems that the mvnwcommand fails. This file is generated by my IDE: IntelliJ IDEA 2018.1. I don't know what it is used for and why does it fail?

看来mvnw命令失败了。这个文件是我的IDE生成的:IntelliJ IDEA 2018.1。我不知道它的用途是什么,为什么会失败?

I already fired an issue in Spring Boot's github issues here, but Spring project said it's Maven wrapper's issue and pointed me here. I don't quite understand what it means. Is it a Maven bug? How to fix the error then?

我已经在 Spring Boot 的 github 问题here 中引发了一个问题,但是 Spring 项目说这是 Maven 包装器的问题,并指出我在这里。我不太明白这是什么意思。这是一个Maven错误吗?那么如何修复错误呢?

采纳答案by Phil Webb

You're missing the .mvnfolder in your git repository. You should have a folder called .mvnwhich contains the files wrapper/maven-wrapper.jar, wrapper/maven-wrapper.propertiesand jvm.config. Perhaps you missed it because it's a hidden folder.

您缺少.mvngit 存储库中的文件夹。你应该有一个文件夹,名为.mvn其中包含的文件wrapper/maven-wrapper.jarwrapper/maven-wrapper.propertiesjvm.config。也许你错过了它,因为它是一个隐藏的文件夹。

Try doing git add -f .mvnfrom the command line then commit and push.

尝试git add -f .mvn从命令行执行,然后提交并推送。

回答by user3083339

Phil's answer is correct. And here is how to create .mvn directory with needed jar inside.
I found the answer here (https://www.baeldung.com/maven-wrapper)

菲尔的回答是正确的。这里是如何创建 .mvn 目录,其中包含所需的 jar。
我在这里找到了答案(https://www.baeldung.com/maven-wrapper

If you have maven and you want to make maven wrapper working, you need to setup maven wrapper:

如果你有 maven 并且你想让 maven 包装器工作,你需要设置 maven 包装器:

mvn -N io.takari:maven:wrapper

It should create .mvn directory and put needed jar in it.

它应该创建 .mvn 目录并将所需的 jar 放入其中。

回答by Badmous

i actually did just mvn clean install and it worked, i am actually using older version of spring 2.0 to be specific

我实际上只是做了 mvn clean install 并且它起作用了,我实际上使用的是旧版本的 spring 2.0 来具体

回答by Suraj Muraleedharan

For me, maven-wrapper.jarwas missing inside .mvn/wrapper/directory. I searched in github for maven-wrapper.jar, downloaded it and placed it inside .mvn/wrapper/, it worked !!!

对我来说,maven-wrapper.jar.mvn/wrapper/目录中丢失了。我在 github 上搜索maven-wrapper.jar,下载并放在里面.mvn/wrapper/,成功了!!!