53

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?

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
hsluoyz
  • 2,489
  • 3
  • 29
  • 55
  • Maybe take a look at [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)... I believe nobody is willing to read and understand your code from zero – 0x1C1B Apr 30 '18 at 16:08
  • This isn't the error, you need to look at the maven output log for "mvn install". – Nyamiou The Galeanthrope Apr 30 '18 at 16:58
  • Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – hsluoyz May 01 '18 at 07:17

6 Answers6

96

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.

Oleksii Volynskyi
  • 1,079
  • 7
  • 5
  • 8
    Although @PhilWebb's answer maybe right, it addressed the diagnosis but not the remedy. This helped, although what is `takari` and is there a standard lib/package? – perennial_noob Jul 19 '19 at 18:32
  • this helped us get our jhispter app working - thanks – Gel Feb 19 '20 at 16:10
  • If you're on Windows, make sure you have the `wrapper/maven-wrapper.jar` – heyomi Nov 18 '21 at 13:36
  • You may check this out: https://github.com/takari/maven-wrapper https://maven.apache.org/wrapper/ ``` lang-powershell mvn wrapper:wrapper ``` – Néstor Waldyd Feb 19 '22 at 01:39
76

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.

Phil Webb
  • 7,485
  • 1
  • 32
  • 33
  • Note that I actually had the .mvn directory already created and still had to do this for some reason. – mslissap May 04 '21 at 19:55
  • 1
    In my case I had the .mvn directory but I needed to install git-lfs to be able to checkout properly maven-wrapper.jar (otherwise it is replaced by a text file) – Rolintocour Sep 22 '21 at 14:59
1

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.

HelloWorld
  • 283
  • 2
  • 10
0
  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
0

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.

-2

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

Badmous
  • 55
  • 1
  • 5