A Quick Introduction to Maven Wrapper

By Deepshikha Sinha and Nishant Madan

Xebia Engineers
Sep 3 · 2 min read

From the day we joined Xebia, we were working on a project with a Maven build using Maven Wrapper. But we were not aware what exactly the Maven Wrapper was. Going deep into the topic, we got to know many interesting things about it. We hope reading through this blog will help beginners to know about the Maven Wrapper.

By default there are various directories/packages created within a Maven Wrapper project. These can be generated by running the following command in the Maven project directory root.

mvn -N io.takari:maven:wrapper

This will create new mvnw and mvnw.cmd files as well as a .mvn folder in your project.

Let us just show you the directory of the Maven project :

Default Project Configuration with Maven

The .mvn folder consists of the optional wrapper jar and the maven-wrapper.properties configuration file with the URLs to download the wrapper jar or the maven zip archive form.

The .mvn folder consists of :

With these files we are not dependent on the specific version of the Maven Wrapper project, if it is not installed on our machine. Also, there is no need to download a specific version of Maven and set the environment variables for that version in our classpath making the maven independent of the machine that we are working on.

Every file in the .mvn folder has its own use :

maven-wrapper.jar file is used to download and invoke maven from the wrapper shell scripts.

maven-wrapper.properties is used to specify the URL Maven should be downloaded from if not already present on the system.

Maven is downloaded by compiling and executing the Java class file MavenWrapperDownloader.java present in the same .mvn folder.

The two generated files mvnw and mvnw.cmd generated by the maven wrapper command are used to run the Maven project without having Maven installed on your machine and present in the classpath. It downloads the correct Maven version if it’s not found (in your user home directory usually).The basic difference in these files is that mvnw is used for the Linux environment whereas mvnw.cmd is used for the windows.

This is it for now about maven wrapper. We hope that this blog proved useful to you and you got to learn about maven wrapper. But keep learning and exploring. As a wise man once said:

When you focus on problems you’ll have more problems.When you focus on possibilities you’ll have more opportunities.

Xebia Engineering Blog

The Xebia Engineering Blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade