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.
use the official maven wrapper
mvn wrapper:wrapper
rather than io.takari:maven:wrapper which is no longer maintained
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.
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.
A mvnw is a maven wrapper. Basically it is a script that decouples maven from your local installation and may add checks and features to the actual mvn command - for the complete explanation check the official maven documentation .
To set it up (assuming you had it running solely with mvn
) it should suffice to run:
mvn wrapper:wrapper
And that should create at least the following new files:
.
├── .mvn
│ └── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── mvnw
└── mvnw.cmd
Then, by evoking mvnw
you'd run everything by that maven-wrapper.jar - completely unattached from you local maven installation.
If the maven-wrapper.jar
is not in place after the command, you probably have a network issue - the most common one is a proxy that needs to be configured.
Initially, the mvn wrapper:wrapper
couldn't fetch the maven-wrapper.jar
for me.
.
├── .mvn
│ └── wrapper
│ └── maven-wrapper.properties
├── mvnw
└── mvnw.cmd
If you take the deep dive into the rabbit hole and check the actual wrapper code , you'll notice there is no default proxy - but you can set a proxy for the java virtual machine by creating a .mvn/jvm.config
file containing:
-Dhttp.proxyHost=proxy.domain.name
-Dhttp.proxyPort=8080
-Dhttps.proxyHost=proxy.domain.name
-Dhttps.proxyPort=8080
With that in place just rerunning the setup command
mvn wrapper:wrapper
fetched everything by itself:
.
├─ .mvn
│ ├── jvm.config
│ └── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── mvnw
└── mvnw.cmd
By now, running the ./mvnw clean install
, should work ok - it did for me (but only for a few days)
One nice day, I came into office and the mvnw
was returnnig the same error you stated....
For me the issue was actually a line ending (LF <-> CRLF) issue in the jvm.config
file.
As the mvnw
script expands the options into an actual command the command would get messed up with a CR splitting it before the classpath option. Since that classpath is where the maven-wrapper.jar (containing the MaveWrapperMain) is passed, the java command couldn't actually get the class.
How did I fix it:
I simply re-created the file containing only LFs and no CRLFs.
Bonus:
As I noticed that this CRLF was introduced by a user that was on a windows machine, I checked some git documentation to avoid repeating the issue, ran the following and advised everyone to do the same:
git config --global core.autocrlf true
Hope this centralizes the steps I found scattered and ends up saving time to someone.
我实际上只是做了 mvn clean install 并且它起作用了,我实际上使用的是旧版本的 spring 2.0 来具体
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.