Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could not find MavenWrapperMain class, but is contained within .m2 in the directory

Tags:

java

maven

So here's a new one, for me… I'm working with one of the Spring Boot guides, and getting the

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

error when running

./mvnw spring-boot:run

(or any Maven Wrapper command)

That said, I see the wrapper jar within .mvn where I would expect it to be.

Has anyone else hit this? It seems like it must be a system-level issue because I've had no issue with this in the past.

Here is the repo I am running this command on: https://github.com/spring-guides/gs-scheduling-tasks.git

like image 913
Thomas Murphy Avatar asked Feb 13 '18 17:02

Thomas Murphy


2 Answers

Initial project is an empty project so when you run ./mvnw spring-boot:run in this folder the message is clear and tells you that there is no main class in the project to run as a Spring Boot application.

If you run the command in the complete folder you run the project which has all the logic of the tutorial.

If you cd in the root folder and you run mvnw from inside complete or initial folders you get that message because it is like you cd to a completely irrelevant folder like /test/project (you can try that).

What mvnw does is tries to find and run a .pom file where in all folders except for complete and initial is not present.

like image 162
ddarellis Avatar answered Oct 11 '22 20:10

ddarellis


I finally figured this out, so posting for posterity:

If the Maven download was corrupted for whatever reason and didn't successfully download (due to loss of connectivity or other reasons), this error will throw.

Mitigation is (within Spring Boot application folder):

rm -rf .mvn
./mvnw spring-boot:run
like image 1
Thomas Murphy Avatar answered Oct 11 '22 20:10

Thomas Murphy