Skip to main content
Java & Maven Setup

Environment Setup

Java & Maven Setup

Reading10 min read

Java & Maven Setup for Selenium

Getting your environment right before writing a single test line saves hours of debugging. This lesson walks you through a professional Java + Maven setup for Selenium WebDriver.

Prerequisites

  • Java JDK 17+: Selenium 4 supports Java 8+, but LTS releases (11, 17, 21) are recommended for production use
  • Maven 3.8+: Dependency and build management
  • IDE: IntelliJ IDEA (recommended) or Eclipse
  • Git: For version-controlling your test project from day one

Installing Java (macOS/Linux)

The cleanest way is via SDKMAN:

curl -s "https://get.sdkman.io" | bash
sdk install java 17.0.10-tem
java -version  # Verify: openjdk version "17.0.10"

On Windows, download from adoptium.net and add JAVA_HOME to your environment variables.

Project Structure with Maven

selenium-tests/
├── pom.xml
├── src/
│   ├── main/java/         (page objects, helpers)
│   └── test/java/         (test classes)
│       └── tests/
│           └── LoginTest.java
└── src/test/resources/
    └── testng.xml

The Essential pom.xml

<dependencies>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.20.0</version>
  </dependency>
  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.10.2</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Why Maven Over Gradle?

Both work. Maven's convention-over-configuration approach makes it easier for teams to onboard new engineers — the directory structure and lifecycle phases are the same in every project. Gradle offers more flexibility but requires more setup for newcomers.

For a team starting fresh, Maven's predictability is usually worth it.