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

JavaSpringMavenSpring BootTravis Ci

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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 2 - Java

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 3 - Java

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 - Java

  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 - Java

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 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhsluoyzView Question on Stackoverflow
Solution 1 - JavaOleksii VolynskyiView Answer on Stackoverflow
Solution 2 - JavaPhil WebbView Answer on Stackoverflow
Solution 3 - JavaHelloWorldView Answer on Stackoverflow
Solution 4 - JavaAkilan TamilarrasuView Answer on Stackoverflow
Solution 5 - JavaXSword24View Answer on Stackoverflow
Solution 6 - JavaBadmousView Answer on Stackoverflow