Download and Install Maven on Windows
- Details
- Written by Nam Ha Minh
- Last Updated on 31 July 2022   |   Print Email
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”: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:Now, open a new command prompt and type mvn -v in the command line. You will see the following output: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.4You will see the following output: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: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:Now, type mvn packagecommand to build and package the project to a Java Archive (JAR) file. You will see the following output: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:
- Maven - how to exclude tests from build
- How to change Java version for Maven project
- Fix Maven Build Error invalid target release
Comments