'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?



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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.

Solution 4:[4]

  1. Adding to what Oleksii Volynskyi,

use the official maven wrapper

mvn wrapper:wrapper

rather than io.takari:maven:wrapper which is no longer maintained

  1. As mentioned by Phil Webb add .mvn folder to the git repository

Solution 5:[5]

In my case, I had the project saved in a folder which route included a character with an accent (in my case "รก"). Removing the accent fixed the problem.

Solution 6:[6]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phil Webb
Solution 2 Oleksii Volynskyi
Solution 3 HelloWorld
Solution 4 Akilan Tamilarrasu
Solution 5 XSword24
Solution 6 Badmous