«I don't know what it is used for»:
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.
«How to fix»:
What is the problem?
Proxy issue:
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)
Class Issue:
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.