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

I have a spring boot project here: https://github.com/jcasbin/jcasbin-springboot-plugin. I encountered the following error in 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 mvnw command 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?

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?


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)

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

mvn -N io.takari:maven:wrapper

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


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

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


For anyone using Windows seeing this error, check if the .mvn folder files got converted to CRLF. If so, changing them to LF will likely fix your problem.