Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of mvnw and mvnw.cmd files?

When I created a Spring Boot application I could see mvnw and mvnw.cmd files in the root of the project. What is the purpose of these two files?

like image 261
shaunthomas999 Avatar asked Aug 02 '16 14:08

shaunthomas999


People also ask

What is MVNW and MVNW CMD?

2.1.mvnw: it's an executable Unix shell script used in place of a fully installed Maven. mvnw. cmd: it's the Batch version of the above script. mvn: the hidden folder that holds the Maven Wrapper Java library and its properties file.

Should I commit MVNW file?

It depends, if you want to use the Maven wrapper or not. If not, then you can delete those files. If you want to use it, then you have to commit the files in the repository, otherwise it doesn't make sense to use it.

What is mvn wrapper?

The Maven Wrapper is an easy way to ensure a user of your Maven build has everything necessary to run your Maven build.

What is .mvn folder?

The . mvn directory is a directory where you can put some Maven configuration files. One of these Maven configuration files is the jvm. config file which can be used to configure the Java VM that is used by Maven to build your project.


2 Answers

These files are from Maven wrapper. It works similarly to the Gradle wrapper.

This allows you to run the Maven project without having Maven installed and present on the path. It downloads the correct Maven version if it's not found (as far as I know by default in your user home directory).

The mvnw file is for Linux (bash) and the mvnw.cmd is for the Windows environment.


To create or update all necessary Maven Wrapper files execute the following command:

mvn -N io.takari:maven:wrapper 

To use a different version of maven you can specify the version as follows:

mvn -N io.takari:maven:wrapper -Dmaven=3.3.3 

Both commands require maven on PATH (add the path to maven bin to Path on System Variables) if you already have mvnw in your project you can use ./mvnw instead of mvn in the commands.

like image 115
Dodge Avatar answered Oct 10 '22 03:10

Dodge


Command mvnw uses Maven that is by default downloaded to ~/.m2/wrapper on the first use.

URL with Maven is specified in each project at .mvn/wrapper/maven-wrapper.properties:

distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip 

To update or change Maven version invoke the following (remember about --non-recursive for multi-module projects):

./mvnw io.takari:maven:wrapper -Dmaven=3.3.9  

or just modify .mvn/wrapper/maven-wrapper.properties manually.

To generate wrapper from scratch using Maven (you need to have it already in PATH run:

mvn io.takari:maven:wrapper -Dmaven=3.3.9  
like image 24
Michal Kordas Avatar answered Oct 10 '22 03:10

Michal Kordas