How to create a simple Java project in Maven

Maven has become a de-facto tool for dependency management. A lot of times we need to create maven project. Let’s see how to create a simple Java project using Maven.

Pre-requisite

  • Java 6+
  • Maven 3.2.5

Here are few assumptions

Package name = com.codezuzu (used for groupId)
App name = maven-app (used for artifactId)

Creating the Project

We shall run maven in non-interactive mode. Here is the command to create the project

$ mvn archetype:generate -DgroupId=com.codezuzu -DartifactId=maven-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This shall create our maven project. Here is how it looks on console

maven-app

Maven shall download few things if not available and shall create the project.

Project Structure

Let’s see how the final structure looks like

maven-app-structure

Java code goes into src/main/java folder, and test class and relevant code goes into src/test/java

3 thoughts on “How to create a simple Java project in Maven

Leave a Reply

Your email address will not be published. Required fields are marked *