How to create a Java project with Maven

  • 07 August 2017
  • ADM


How to create a Java project with Maven - images/logos/maven.jpg


In this tutorial will present how to create a Java project with Maven.

The tools used in this tutorial are:

  • Maven 3.3
  • Eclipse Neon
  • Java 1.8

Note: Any versions will do the work.

If you need help to install any of the tools used in this tutorial please check How to prepare a Windows Java Development Machine for Java and Eclipse installation or the Maven installation tutorials (Windows, MacOS).

Create a Project

To create the project structure and the minimum code for the application run the following command from the terminal(Linux or macOS) or command prompt (Windows):

# mvn archetype:generate -DgroupId=com.admfactory -DartifactId=javatest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

The maven-archetype-quickstart archetype will create all the project and files needed.

You can see an output that looks like

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
Downloaded: (5 KB at 9.0 KB/sec)
Downloaded: (703 B at 8.4 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: D:\Repositories\Bitbucket\
[INFO] Parameter: package, Value: com.admfactory
[INFO] Parameter: groupId, Value: com.admfactory
[INFO] Parameter: artifactId, Value: javatest
[INFO] Parameter: packageName, Value: com.admfactory
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: D:\Repositories\Bitbucket\\javatest
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.975 s
[INFO] Finished at: 2017-07-04T23:09:04+03:00
[INFO] Final Memory: 15M/193M
[INFO] ------------------------------------------------------------------------

Now depending if all necessary plugins are already installed or not, the output can be longer and the process might take longer.

The project folder structure looks like this:

│   pom.xml
    │   └───java
    │       └───com
    │           └───admfactory

A minimum hello world application is created. The project includes a minimum pom.xml file

<project xmlns="" xmlns:xsi=""

The application is really simple and is only printing the "Hello World!" text.

package com.admfactory;

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

Import in Eclipse

To import the project in Eclipse, first you need to create the Eclipse project file by running the following command:

# mvn eclipse:eclipse

After this you can import from Eclipse: select "File -> Import… -> General->Existing Projects into Workspace"

Update Java version

To update the Java version the maven-compiler-plugin need to be added to the pom.xml. Also you could update the Unit test to the latest version (4.12 at the point when the article was written).


To update the project from the command line navigate to the project folder and run again the command:

# mvn eclipse:eclipse

Maven Packaging

To create the jar file the following command needed to be executed.

# mvn package

The jar file will be generated into /target folder.

Run the Application

To run the application from the command line, execute the following command:

# java -cp target\javatest-1.0-SNAPSHOT.jar com.admfactory.App
Hello World!