You know, Maven is a very popular Java build tool. It is actually a software project management and comprehension tool. Developers love using Maven as it greatly simplifies dependency management and build process of any Java projects.

In this quick post, I’d like to show you how to get started with Maven by downloading, installing Apache Maven on Windows operating system. Then you’ll learn how to create and build a simple Java project using Maven.

NOTE: you must have JDK pre-installed in order to run Maven command line tool. If not, kindly follow this guide.

 

1. Download and Install Apache Maven on Windows

Click this link to visit the official download page of Maven. Then click the link next to “Binary zip archive”:

download maven zip file

This will download the binary distribution of Maven in Zip format. Then extract the zip file to a directory, say G:\apache-maven-3.8.6.

Next, you need to update system environment variable so you can use Maven command line tool everywhere in the command line.

Open the Environment Variables dialog and create a new system variable named MAVEN_HOME with value is the absolute path to the directory where Maven zip file is extracted:



create maven home variable

Then update the PATH system variable, adding an entry as shown below:

add maven home to path variable

Click OK to apply the change.
Now, open a new command prompt and type mvn -v in the command line. You will see the following output:

run mvn v command

It shows the version of Apache Maven, Java and operating system - as you can see. Congratulations! You have successfully got Maven up and running. The next step is creating your first Java project using Maven command line tool.


2. Create and Build a simple Java Project using Maven

Let me show you how to get started with Maven by creating and building a simple Java project. In Windows command prompt, type the following command:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4

You will see the following output:

generate Java project using Maven

You see, Maven is creating a new Java project in interactive mode, so provide the information about groupId, artifactId, version and package name for your project - as shown in the screenshot above. Then type Y to confirm.

If you see the following output, that means Maven has created the project successfully:

maven create project success

Then you can see Maven generated the project under MyJavaApp directory. Explore this directory to see what was generated (pom.xml, App.java and AppTest.java).

Next, change the current directory to the project one using cd MyJavaApp command. And type tree /f to see the project directory structure, as shown below:

maven project structure

Now, type mvn packagecommand to build and package the project to a Java Archive (JAR) file. You will see the following output:

maven package build project

The result is a JAR file named MyJavaApp-1.0.jar created in the target directory. Then you can type the following command to run it:

java -cp target\MyJavaApp-1.0.jar net.codejava.App

That’s my guide to download, install Maven on Windows. You also learned how to create your first Java project with Maven command line tool. I hope you find this article helpful to get started with Maven.

To see the steps in action, watch the following video:

Video:

 

Other Maven Articles:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment

   


Comments 

#1abdurazak2023-11-03 17:41
gGood application for the most important thing to do is to prioritize.
Quote