A Maven project has a specific folder structure and a pom.xml file that defines your project and its dependencies. IntelliJ can create this automatically.
java-practice | Location: choose any folder | Language: Java | Build system: Maven | JDK: 17 (temurin-17)com.practice | ArtifactId: java-practiceIntelliJ creates this folder structure:
java-practice/
├── pom.xml ← Project config + dependencies
├── src/
│ ├── main/
│ │ └── java/ ← Your main code goes here
│ └── test/
│ └── java/ ← Your test code goes here
└── target/ ← Compiled files (auto-generated)The pom.xml (Project Object Model) is the heart of every Maven project. It defines your project name, Java version, and all libraries (dependencies) your project uses.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.practice</groupId>
<artifactId>java-practice</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>
<!-- Dependencies will go here later -->
</dependencies>
</project>| Element | What It Means | Example |
|---|---|---|
| groupId | Your organization/package name | com.practice |
| artifactId | Project name | java-practice |
| version | Project version | 1.0-SNAPSHOT |
| maven.compiler.source | Java version to compile with | 17 |
| dependencies | External libraries your project needs | Selenium, TestNG, etc. |
When you add a dependency to pom.xml, Maven downloads it automatically from Maven Central Repository (https://mvnrepository.com). You will add Selenium and TestNG later in this course. For now, here is what adding a dependency looks like:
<dependencies>
<!-- Example: This is how you will add Selenium later -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.25.0</version>
</dependency>
<!-- Example: This is how you will add TestNG later -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>Do NOT add Selenium/TestNG dependencies now — you will add them when you reach those chapters. Right now, your project only needs Java basics with no external libraries.
Go to https://mvnrepository.com and search for any library. It shows you the exact XML to paste into your pom.xml. Example: search "selenium-java" → click the latest version → copy the Maven dependency XML.
You can run these commands in IntelliJ's Terminal tab (bottom of the window) or in your system terminal:
| Command | What It Does |
|---|---|
| mvn compile | Compiles your Java code |
| mvn test | Compiles and runs all tests |
| mvn clean | Deletes the target/ folder (compiled files) |
| mvn clean test | Cleans, compiles, and runs tests |
| mvn clean install | Cleans, compiles, tests, and packages your project |
Exercise 1: Create a new Maven project in IntelliJ following the steps above. Verify that the pom.xml file exists and contains <maven.compiler.source>17</maven.compiler.source>.
Exercise 2: Open IntelliJ's Terminal (bottom tab) and run mvn compile. It should show "BUILD SUCCESS". If it fails, check that JAVA_HOME is set correctly.