Create a Simple Maven Project using Command Line

In this tutorial, we learn how to create a simple standalone Java maven project using the Maven Archetype plugin.

Note that we are creating a simple Maven project from the command line using Maven.

Note that this is not a web application. If you want to create a Maven web application then check out Create a Simple Maven Web Application using Command-Line.

You can also create Maven projects in Eclipse IDE. Check out below articles:


- Make sure that you have installed Java 8+.

- Make sure that you have installed Maven and configured an environment path ( if not check out How to install Maven on Windows 10)

1. Creating a Maven Project 

Let's start a new Maven project, we use the Maven Archetype plugin from the command line.

You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:
mvn archetype:generate -DgroupId=com.companyname.projectname  
Note that whole command should be single line. After build success, we will see below output in command line console.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:23 min
[INFO] Finished at: 2018-06-20T10:50:40+05:30
[INFO] ------------------------------------------------------------------------
Note that our project name: simple-maven-project 

2. Maven Standard Directory Layout 

Once we’ve generated a project, take a look at the directory structure Maven created under the simple directory:
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- mycompany
    |               `-- app
    |                   `--
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
This generated directory adheres to the Maven Standard Directory Layout. let's understand these few basic directories:
  1. The Maven Archetype plugin creates a directory simple-maven-project that matches the artifactId. This is known as the project’s base directory.
  2. Every Maven project has what is known as a Project Object Model (POM) in a file named pom.xml. This file describes the project, configures plugins, and declares dependencies.
  3. Our project’s source code and resources are placed under src/main. In the case of our simple Java project this will consist of a few Java classes and some properties file. In web project, this could be the document root of a web application or configuration files for an application server. In a Java project, Java classes are placed in src/main/java and classpath resources are placed in src/main/resources.
  4. Our project’s test cases are located in src/test. Under this directory, Java classes such as JUnit or TestNG tests are placed in src/test/java, and classpath resources for tests are located in src/test/resources.


The Maven Archetype plugin generated a single class com.companyname.projectname.App,which prints 'Hello World!'
package com.companyname.projectname;

 * Hello world!
public class App 
    public static void main( String[] args )
        System.out.println( "Hello World!" );

4. Simple Project Object Model(pom.xml)

Every Maven project has what is known as a Project Object Model (POM) in a file named pom.xml. This file describes the project metadata, configures plugins, and declares dependencies.
<project xmlns="" xmlns:xsi=""

5. Maven Build the Project

Go to the project directory and run the following commands to build this Maven project:
> cd simple-maven-project
> mvn install
The command line will print out various actions, and end with the following:
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.640 s
[INFO] Finished at: 2018-06-20T11:53:12+05:30
[INFO] ------------------------------------------------------------------------
You’ve just created, cleaned, compiled, tested, packaged, and installed the simplest possible Maven project.

6. Run Packaged JAR

You may test the newly compiled and packaged JAR with the following command:
java -cp target/simple-maven-project-1.0-SNAPSHOT.jar com.companyname.projectname.App
Hello World!


In this tutorial, we have seen how to create a simple standalone Maven project using the command line.

The source code for this simple maven web project is available on GithubGithub Repository : Simple Maven Application