EduArn – Online & Offline Training with Free LMS for Python, AI, Cloud & More

Maven Project Structure, POM.xml & Dependencies Explained | Beginner Guide

Maven Project Structure, POM.xml & Dependencies Explained | Beginner Guide

Maven Project Structure, POM.xml & Dependencies Explained: Complete Beginner Guide

If you are learning Java, Selenium, automation testing, or software development, you will probably come across Maven very quickly.

At first, a Maven project can look confusing. You may see folders such as src/main/java, src/test/java, resources folders, and a file called pom.xml.

Then you may ask:

  • What is the Maven project structure?
  • What is pom.xml?
  • Where should Java code go?
  • Where should test code go?
  • What are Maven dependencies?
  • How does Maven download libraries?
  • What do commands like mvn clean, mvn test, and mvn package do?

This guide explains all of these concepts in simple language with a practical Eduarn retail training project.

Watch the Maven Tutorial

Before we get into the details, you can watch the complete beginner-friendly video tutorial here:

In this video, we build a simple Maven project and explain the project structure, pom.xml, dependencies, and essential Maven commands.

What Is Maven?

Apache Maven is a build automation and dependency management tool commonly used for Java projects.

In simple terms, Maven helps you manage the libraries your project needs and provides commands for common tasks such as compiling code, running tests, cleaning build files, and packaging an application.

Imagine that your Java application needs several libraries. You might need JUnit for testing, Selenium for browser automation, Jackson for JSON processing, or Spring for application development.

Instead of manually downloading and managing every library, you can define what your project needs in pom.xml.

Simple idea:

Your project needs a library → define the dependency in pom.xml → Maven manages the dependency.

A Quick Maven Story

When I was working on my first project back in 2004, managing project libraries and configuration felt much more difficult.

There was more manual work involved, especially when you were new to the technology.

Today, tools such as Maven make this process much easier. With a properly configured pom.xml and a few Maven commands, you can manage dependencies, run tests, clean build output, and package your project.

If Maven looks confusing when you first start, don't try to learn everything at once. Begin with four concepts:

Project Structure → POM → Dependencies → Maven Commands

Maven Project Structure

Let's use a simple project called:

eduarn-retail-training

A typical structure can look like this:

eduarn-retail-training


│
├── pom.xml
│
└── src
├── main
│ ├── java
│ └── resources
│
└── test
├── java
└── resources

src/main/java

This is where your main Java application code normally lives.

For example:

package com.eduarn.retailtraining;


public class Product {

private String productName;
private double price;

public Product(String productName, double price) {
    this.productName = productName;
    this.price = price;
}

public double getPrice() {
    return price;
}


}

In our example, the package is:

com.eduarn.retailtraining

This keeps the example connected naturally with the Eduarn retail training project.

src/main/resources

This folder is generally used for resources required by the application.

Examples include:

application.properties


product-data.json
config.properties

src/test/java

This is where your Java test classes normally go.

For example:

@Test


void verifyProductPrice() {

Product product =
    new Product("Laptop", 50000);

System.out.println(product.getPrice());


}

src/test/resources

This folder can contain resources specifically required by your tests.

Easy rule to remember:

main = application

test = testing

What Is pom.xml?

One of the most important files in a Maven project is:

pom.xml

POM stands for Project Object Model.

You can think of pom.xml as the main instruction and configuration file for your Maven project.

It can define information such as:

  • Project identity
  • Project version
  • Java version
  • Project dependencies
  • Build plugins
  • Other Maven configuration

groupId

<groupId>com.eduarn</groupId>

The groupId generally identifies the organization or project group. In this example, we use com.eduarn.

artifactId

<artifactId>eduarn-retail-training</artifactId>

The artifactId identifies the Maven project or artifact.

version

<version>1.0-SNAPSHOT</version>

The version identifies the current version of the project.

Easy way to remember:

Group → Project → Version

What Are Maven Dependencies?

Dependencies are external libraries that your project needs.

For example, if our Eduarn retail training project needs JUnit for testing, we can define JUnit as a Maven dependency.

<dependency>

<groupId>org.junit.jupiter</groupId>

<artifactId>junit-jupiter</artifactId>

<version>5.10.2</version>

<scope>test</scope>


There are four important pieces here:

  • groupId — identifies the library group or provider.
  • artifactId — identifies the library.
  • version — specifies the library version.
  • scope — defines where the dependency is used.

Maven and Selenium

If you're learning Selenium automation with Java, Maven is commonly used to manage Selenium dependencies.

A Selenium dependency can look like this:

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-java</artifactId>

<version>YOUR_VERSION</version>


The exact dependency version should be selected according to the version appropriate for your project.

Don't memorize the XML.

Understand the process:

Project needs a library → Add dependency → Maven manages it.

Complete Maven pom.xml Example

Here is a simple Maven configuration for our Eduarn retail training example:

<?xml version="1.0" encoding="UTF-8"?>




<modelVersion>4.0.0</modelVersion>

<groupId>com.eduarn</groupId>
<artifactId>eduarn-retail-training</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.10.2</version>
        <scope>test</scope>
    </dependency>

</dependencies>


Important Maven Commands for Beginners

1. mvn clean

mvn clean

This removes previous build output, including the Maven target directory when applicable.

2. mvn test

mvn test

This compiles the relevant code and runs the project's tests during the Maven test phase.

3. mvn package

mvn package

This runs the Maven lifecycle through the package phase and creates the project's package output according to its build configuration.

Start with these three commands:

mvn clean → Clean

mvn test → Test

mvn package → Package

Maven Project Structure: Quick Recap

eduarn-retail-training


│
├── pom.xml
│
└── src
├── main
│ ├── java
│ └── resources
│
└── test
├── java
└── resources
  • src/main/java → Application code
  • src/main/resources → Application resources
  • src/test/java → Test code
  • src/test/resources → Test resources
  • pom.xml → Maven project configuration
  • Dependencies → Libraries required by the project

Why Learn Maven?

Maven is worth understanding because it appears frequently in Java development and automation projects.

Once you understand the project structure, POM file, dependencies, and basic Maven commands, many Java projects become easier to navigate.

This knowledge is especially useful when working with Java automation frameworks, Selenium projects, JUnit testing, CI/CD pipelines, and larger development teams.

Learn More with Eduarn

If you're interested in practical Java, Selenium, automation testing, DevOps, and retail technology training, explore more learning content from Eduarn.

Continue Learning

Watch the complete Maven tutorial above and follow along by creating your own Maven project.

What should we cover next?

  • Maven Lifecycle
  • Maven Plugins
  • Maven Profiles
  • Selenium + Maven Project
  • Complete Java Automation Framework

Comment below and let us know.

Final Takeaway

You don't need to become a Maven expert in one day.

Start by understanding these four concepts:

Project Structure → pom.xml → Dependencies → Maven Commands

Once these basics are clear, you can gradually move on to Maven lifecycle, plugins, profiles, Selenium automation, and larger Java projects.

Keep learning, keep building, and practice by creating small real-world projects.

🚀 Keep Learning with Eduarn

Explore more practical technology and retail training resources at Eduarn.com.

Build your skills one concept at a time and turn your learning into practical, real-world knowledge.

👉 Explore Eduarn.com

1 comment:

  1. What was the most confusing part of Maven when you first started — project structure, pom.xml, or dependencies? 👇 #eduarn

    ReplyDelete