Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Java
  • Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
  • Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
  • Java Hello World with Maven: What the JDK Does and What Maven Adds
  • Java Variables, Keywords and Naming Rules
  • Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
  • Java Primitive Types and Memory: What int x = 5 Really Does
  • Java Strings and Text Blocks: Quotes, Concatenation and parseInt
  • Java Operators: Arithmetic, a++ vs ++a, Precedence, && || and the Ternary
  • Java Type Casting: Widening, Narrowing and Converting Text to Numbers
  • Java Practice Lab: A Cafe Bill with Variables, Operators and Casting
  • Java if, else and switch: Braces, Else-If Ladders and the Modern Switch
  • Java Loops: for, while, do-while and for-each
  • Java break, continue and Nested Loops
  • What's New in Java 21 to 25: Compact Source Files and Sequenced Collections
  • Java Arrays: Indexes, Default Values, Loops and 2D Grids
  • Java Methods and Overloading: Parameters, return and Pass-by-Value
  • Java Scope, Code Blocks and the Call Stack
  • Read User Input in Java with Scanner (and the Leftover Enter Trap)
  • Java Practice Lab: A Gym Weekly Tracker with Loops, Arrays and Methods
  • Debugging Java in IntelliJ: Stack Traces, Breakpoints and a Better AI Prompt
  • Java var: Let Java Infer the Type
  • Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
  • Java Classes and Objects: One Blueprint, Many Cars
  • Java Constructors and the this Keyword
  • Java Instance Methods, Getters, Setters and toString
  • Java static: Fields, Methods and Blocks Shared by the Whole Class
  • Java Packages and Imports: Every Class Has an Address
  • Java Access Modifiers and Encapsulation: Private Data, Public Methods
  • Java final and Immutable Objects: Assign Once, Share Safely
  • Java Strings as Objects: The String Pool, == vs equals, StringBuilder and printf
  • Java Practice Lab: A Library Book Catalogue with final Fields and StringBuilder
  • Java Inheritance: extends, super and the Order Objects Are Built
  • Java Method Overriding, @Override and the Object Class
  • Java Polymorphism: Upcasting, Dynamic Dispatch and Downcasting
  • Java Composition: Has-A vs Is-A
  • Java Abstract Classes: A Parent That Leaves One Blank
  • Java Interfaces: Contracts and Multiple Inheritance
  • Java Nested, Inner and Anonymous Classes
  • Java Enums with Fields, Methods and switch
  • Java Practice Lab: Payment Processing with an Interface, an Abstract Class and an Enum
  • Java Records: A Whole Data Class in One Line
  • Java Sealed Classes and Interfaces
  • Java Pattern Matching with instanceof and switch
  • Java Record Patterns: Unpacking a Record
  • Java equals and hashCode: Why a HashSet Needs Both
  • From Arrays to Collections: The Java Collections Framework Map
  • Java Wrapper Classes and Autoboxing
  • Java ArrayList: The Stretchy Array
  • Java LinkedList vs ArrayList: Nodes or an Array
  • Java Sets: HashSet, LinkedHashSet and TreeSet
  • Java Sorting with Comparable and Comparator
  • Java Maps: HashMap, LinkedHashMap and TreeMap
  • Java Stacks, Queues and Deques: ArrayDeque and PriorityQueue
  • Choosing a Java Collection: Immutable and Sequenced Collections
  • Java Exception Handling: try, catch and finally
  • Java throw, throws, Checked vs Unchecked and Custom Exceptions
  • Java try-with-resources and Clean Error Handling
  • Java Generics: Type-Safe Containers
  • Java Generic Methods, Bounded Types and Wildcards
  • Java Lambdas and Functional Interfaces
  • Java Built-in Functional Interfaces: Predicate, Function, Consumer, Supplier
  • Java Optional: Saying Maybe Without null
  • Java Streams I: filter, map and reduce
  • Java Streams II: Collectors, groupingBy and flatMap
  • Why Concurrency: Processes, Threads and the Main Thread in Java
  • Creating Threads in Java: Thread, Runnable and Lambdas
  • Java Thread Lifecycle: sleep, join and interrupt
  • Java Race Conditions and synchronized
  • Java volatile and Atomic Variables
  • Java ExecutorService and Thread Pools
  • Java Callable, Future and CompletableFuture
  • Java Locks, Deadlock and tryLock
  • Java Concurrent Collections and Virtual Threads
  • Why Slow Work Belongs off the Request Thread: 202 Accepted and a Job Id in Spring Boot
  • Virtual Threads in Spring Boot: One Property, and the Connection Pool Trap
  • @Async, Named TaskExecutors and Structured Concurrency in Spring Boot
  • Java Files and Directories with NIO.2: Path and Files
  • Reading and Writing Text Files in Java
  • Java Structured Data: Reading and Writing JSON and CSV
  1. Blog
  2. /
  3. Java
  4. /
  5. Basics

Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle

Open a plain project and a Maven project in IntelliJ, read an invoice app's pom.xml, follow jackson-databind from Maven Central into ~/.m2, and see why each lifecycle phase runs the ones before it.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Basics

What you will learn

  • Run a plain project and a Maven project in IntelliJ by finding main
  • Read a pom.xml: coordinates, properties, dependencies and test scope
  • Explain how a dependency travels from Maven Central to the local repository
  • Run compile, test, package and exec:java and say what each phase does

Before you start

  • Java Hello World with Maven and the JDK

Most Java Foundation projects run the same way: find the file with main and click the green arrow. Maven projects add one file, pom.xml, and a fixed folder layout. This article opens both kinds of project, reads a real pom.xml, and runs the Maven lifecycle on a small invoice app.

Open a project, find main

A plain project has a src folder, one file and no pom.xml. Which file do you run? The one with the small green play arrow next to its main method.

public class WelcomeNote {
    public static void main(String[] args) {
        // No pom.xml, no Maven: IntelliJ compiles this with the project SDK
        System.out.println("Welcome to the course, Emma Clark!");
        System.out.println("Running on Java " + System.getProperty("java.version"));
    }
}
Welcome to the course, Emma Clark!
Running on Java 25.0.x

IntelliJ compiles the class, then runs it. The second line prints your JDK's version, so the exact number depends on your machine.

The same steps in a Maven project

A Maven project's tree goes deeper: code in src/main/java, tests in src/test/java, and pom.xml at the top. Finding main works exactly the same. InvoiceApp only uses the JDK, so you can run it with the green arrow and no Maven command:

package org.studyeasy.s02l03;

public record Line(String item, int qty, double price) {
    public double total() {
        return qty * price;
    }
}
package org.studyeasy.s02l03;

import java.util.List;

public class InvoiceApp {
    public static void main(String[] args) {
        List<Line> lines = List.of(
                new Line("Keyboard", 2, 45.00),
                new Line("Monitor", 1, 189.99),
                new Line("USB-C cable", 3, 9.50));
        System.out.println("Invoice INV-1042");
        double sum = 0;
        for (Line line : lines) {
            System.out.printf("%-12s %6.2f%n", line.item(), line.total());
            sum += line.total();
        }
        System.out.printf("Total: %.2f%n", sum);
    }
}
Invoice INV-1042
Keyboard      90.00
Monitor      189.99
USB-C cable   28.50
Total: 308.49

Don't worry about record, List or printf yet; they all come later in the course. Here the point is the project around the code.

The pom.xml file

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.studyeasy</groupId>
    <artifactId>invoice-app</artifactId>
    <version>1.0.0</version>

    <properties>
        <maven.compiler.release>25</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.19.2</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>6.1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <!-- build / plugins section shown further down -->
</project>
  • Three words name the project. groupId is who made it, artifactId is what it is, version is which build.
  • Properties. maven.compiler.release sets the Java version the code is compiled for: 25.
  • Dependencies are named with the same three words. jackson-databind turns Java objects into JSON. junit-jupiter is for testing, and its scope is test: only the tests use it, so the app itself doesn't carry it.

How a dependency arrives

pom.xml lists jackson-databind. Maven checks the local repository in ~/.m2. If the jar is missing, it downloads it once from Maven Central, together with jackson-annotations and jackson-core, then puts the jars on the project classpath. pom.xml jackson-databind Local repository ~/.m2 on your PC Maven Central remote, public download once missing? classpath: databind, core, annotations Next build: the jar is already in ~/.m2, so nothing is downloaded again.
A dependency is fetched once from Maven Central, cached locally and reused.

Maven first looks in the local repository, a folder on your own computer, where the three words become nested folders. If the jar isn't there, Maven downloads it once from Maven Central and keeps it. The project points to it on its classpath. Two more jars come along, jackson-annotations and jackson-core, because jackson-databind needs them.

Now the code can use Jackson:

package org.studyeasy.s02l03;

import com.fasterxml.jackson.databind.ObjectMapper;

public class InvoiceJson {
    public static void main(String[] args) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        Line line = new Line("Monitor", 1, 189.99);
        String json = mapper.writeValueAsString(line);
        System.out.println(json);
        Line back = mapper.readValue(json, Line.class);
        System.out.println("Read back: " + back.item());
    }
}
{"item":"Monitor","qty":1,"price":189.99}
Read back: Monitor

The lifecycle: compile, test, package

Open the Maven panel (the M on the right edge). It lists lifecycle phases. Double-click one to run it.

compile

Maven first handles the resources step (there's no resources folder, so it skips it). Then the compiler turns the three source files into class files in a new target folder. BUILD SUCCESS. The program is built, but nothing has run.

test

The test code is compiled into its own folder, target/test-classes. Then the surefire plugin finds LineTest and runs it:

package org.studyeasy.s02l03;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class LineTest {
    @Test
    void totalIsQuantityTimesPrice() {
        Line keyboard = new Line("Keyboard", 2, 45.00);
        assertEquals(90.00, keyboard.total(), 0.001);
    }

    @Test
    void oneItemCostsItsPrice() {
        Line monitor = new Line("Monitor", 1, 189.99);
        assertEquals(189.99, monitor.total(), 0.001);
    }
}
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

If even one test failed, the build would stop here.

package

package runs the tests first, and only when both pass does it build the jar in target. The artifactId and version make up the file name, so you can tell which build it is.

Each phase runs the ones before it

PhaseWhat it does
validatechecks pom.xml
compilecompiles the main code
testruns the tests
packagebuilds the jar
verifyextra checks
installcopies the jar into your local repository
deployuploads it to a shared repository

Run test and Maven goes through validate, compile and test in order. Run package and it does those three again, then builds the jar. Two commands sit outside this chain: clean deletes target so you can build fresh, and site makes an HTML report about the project. To start with, compile, test and package are all you need.

Run the app with exec:java

No phase above printed the invoice. For that there's the exec plugin, and pom.xml must name the class to start:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.6.4</version>
            <configuration>
                <mainClass>org.studyeasy.s02l03.InvoiceApp</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

In the Maven panel under Plugins, double-click exec:java. It starts main with the classes that compile built, and the same invoice prints between Maven's own lines, total 308.49.

Common mistakes

  • No mainClass in the exec plugin. Maven doesn't know which main to start. Check this first when exec:java fails.
  • Expecting package to skip tests. It runs them first; a failing test means no jar.
  • Using a test-scoped library in main code. JUnit with scope test isn't available to src/main/java.

Recap

PieceRemember
Running anythingFind main, click the green arrow
pom.xmlNames the project, sets Java 25, lists dependencies
DependenciesFrom Maven Central once, cached in ~/.m2
LifecycleEach phase runs the ones before it
exec:javaRuns the mainClass named in the pom

Keep going in Java · 5 of 79

Previous
Java Variables, Keywords and Naming Rules
Next post
Java Primitive Types and Memory: What int x = 5 Really Does
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program

Install JDK 25 (Microsoft Build of OpenJDK) with JAVA_HOME, install IntelliJ IDEA, then point a run configuration at the JDK and the main class and run Hello World.

Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA

Open IntelliJ's AI Chat, pick Claude Agent (the agent behind Claude Code) or Copilot and a model, ask in plain words for Main.java to print the date and time, review the change, and run it.

Java Hello World with Maven: What the JDK Does and What Maven Adds

javac compiles HelloWorld.java into bytecode and java runs it on the JVM. Maven adds one pom.xml, the same folders in every project and one build command. Then a real Maven Hello World in IntelliJ.

Java Variables, Keywords and Naming Rules

A variable is a labelled jar that holds one value at a time. Four small programs show declaring, reassigning, the names Java accepts, the keywords it reserves, and why daysUntilLaunch beats d.

On this page

  • Open a project, find main
  • The same steps in a Maven project
  • The pom.xml file
  • How a dependency arrives
  • The lifecycle: compile, test, package
  • compile
  • test
  • package
  • Each phase runs the ones before it
  • Run the app with exec:java
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.