how to use mvnw command for first project setting

Viewed 420

I am new to maven and have some basical questions. When I see some projects, there is mvnw file included. What I know is I dont need to install maven on my local if I use mvnw. My question is:

  • what will happen when I firstly execute mvnw install? maven with certain version is automatically installed on my local?

  • can I use like mvn compile instead of mvnw compile after executing mvnw install?

Thanks in advance.

1 Answers

what will happen when I firstly execute mvnw install? maven with certain version is automatically installed on my local?

The mvnw command will look for maven-wrapper.jar in the .mvn/wrapper directory. It will automatically download this jar file if it is not present there. We can consider this step as installing maven in the local machine just for this project. And the version of maven-wrapper.jar installed depends on the configuration in the mvnw command. On the other hand, if the maven-wrapper.jar is already present in the ./mvn/wrapper directory, the mvnw command simply uses it.

can I use like mvn compile instead of mvnw compile after executing mvnw install?

If you have maven installed in your local machine, you certainly can use mvn compile instead of mvnw compile, as long as the version of maven installed in the local machine is compatible with the project. However this can cause problems if the maven installed in the local machine is an older version and the project requires a newer version, or the the other way around.

Related