Java SE: Create Maven Project

Maven and Java

javase
maven
code
project
How to create a Maven Project
Author

albertprofe

Published

Tuesday, June 1, 2021

Modified

Friday, November 1, 2024

1 Create Maven Project

To create a Maven project with a standard directory structure using IntelliJ IDEA, you can follow these steps:

  1. Install the Maven plugin in IntelliJ IDEA.
    1. Open IntelliJ IDEA and navigate to the Plugins settings.
    2. Search for Maven and install the plugin.
  2. In IntelliJ IDEA, click Create New Project.
    1. In the New Project dialog, select Maven Archetype from the list of Generators.
    2. Select the maven-archetype-quickstart archetype. This archetype creates a standard Maven project with a directory structure for source code and unit tests.
    3. Remember to use apache archetype (template).
  3. Choose from system or download the JDK to use
  4. Click Advanced Settings and enter the GroupId and ArtifactId for your project. These are used to identify your project uniquely across all projects.
  5. Click Create to create the project.

Catalog

specify which Maven repository you want to use in your project.

The internal Maven catalog is a default one. You can also select the local repository that is located in the .m2 directory, or you can select Maven central repository.

Your project will be created with the following directory structure:

  my-project
  ├── pom.xml
  └── src
      ├── main
      │   └── Person.java
      │       Account.java
      │       AccountManager.java    
      └── test
          └── AccountManagerTest.java
          

The src/main/java directory is where you should put your Java source code, and the src/test/java directory is where you should put your unit tests.

Maven project folder-tree

Maven project folder-tree

To specify the version of Maven to use, you can edit the pom.xml file and add a <version> element to the <project> element. For example:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>my-project</artifactId>
  <version>3.6.3</version>
  ...
</project>

This will use version 3.6.3 of Maven for the project.

2 Step-by-step screenshots

2022-12-14

Slider-presentation Create project Java SE Maven

2024-01-14

Create Maven JavaSE Project Idea 2024: New Project wizard

Create Maven JavaSE Project Idea 2024: Project structure
Figure 1: Create Maven JavaSE Project Idea 2024

IntelliJ IDEA 2023.3.2 (Community Edition)

Build #IC-233.13135.103, built on December 20, 2023 Runtime version: 17.0.9+7-b1087.9 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.15.0-91-generic

3 Idea configurations

Create Maven JavaSE Project Idea 2024: Idea configurations, File

Create Maven JavaSE Project Idea 2024: Idea configurations, File

Create Maven JavaSE Project Idea 2024: Project structure,SDK and lenguage level

Create Maven JavaSE Project Idea 2024: Project structure,SDK and lenguage level

Create Maven JavaSE Project Idea 2024: modules and sources

Create Maven JavaSE Project Idea 2024: modules and sources

Create Maven JavaSE Project Idea 2024: modules and dependencies

Create Maven JavaSE Project Idea 2024: modules and dependencies

4 What did we create?

Anatomy of our first Class

Anatomy of our first Class

This Java code defines a class named “HelloWorld” with a main method. When executed, it prints “Hello World!” to the console using the System.out.println statement.

The main method serves as the entry point for the program.

This simple program is a common introductory example, demonstrating the basic structure of a Java application and how to output text to the console.

Back to top