JDK + Maven Setup
Before writing a single line of Spring Boot code, you need Java and Maven installed. This guide takes you from zero to a working Java development environment.
JVM (Java Virtual Machine) = the land your house sits on โ it runs Java bytecode on any OS.
JRE (Java Runtime Environment) = the house itself โ everything needed to run Java programs.
JDK (Java Development Kit) = the house + construction tools (hammer, saw, blueprint) โ everything needed to build Java programs.
Maven = the delivery truck that brings all building materials (libraries) to your construction site automatically.
| Tool | Full Name | Purpose | Who Needs It |
|---|---|---|---|
| JVM | Java Virtual Machine | Runs compiled Java (.class) files | Everyone |
| JRE | Java Runtime Environment | JVM + standard libraries | End users |
| JDK | Java Development Kit | JRE + compiler (javac) + tools | Developers โ |
| Maven | Apache Maven | Build tool + dependency manager | Developers โ |
Download JDK 21
Go to adoptium.net (Eclipse Temurin โ free and enterprise-ready). Choose:
Version: 21 (LTS) ยท OS: Windows/Mac/Linux ยท Architecture: x64
Download the .msi installer (Windows) or .pkg (Mac) or .tar.gz (Linux).
Run the Installer (Windows)
Double-click the .msi file. Click Next โ Next โ Accept the default install location (C:\Program Files\Eclipse Adoptium\jdk-21...) โ Finish.
Install on Mac (using Homebrew)
Install on Ubuntu/Linux
Open Environment Variables
Press Win + S โ type "environment variables" โ click "Edit the system environment variables" โ click "Environment Variables" button.
Add JAVA_HOME
Under "System variables" โ click New:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Eclipse Adoptium\jdk-21.0.x.x-hotspot (your exact folder)
Add Java to PATH
In System variables, find Path โ Edit โ New โ add:
%JAVA_HOME%\bin
Click OK on all dialogs.
Open a new terminal (Command Prompt or PowerShell on Windows, Terminal on Mac/Linux) and run:
Expected output:
Also verify the compiler:
java works but not javac, you have JRE installed, not JDK. Reinstall using the JDK installer.Install on Windows
Download Maven
Go to maven.apache.org/download.cgi โ download the Binary zip archive (e.g., apache-maven-3.9.x-bin.zip).
Extract and Place
Extract the zip to C:\Program Files\Apache\maven (create the folder). You should see C:\Program Files\Apache\maven\bin\mvn.cmd.
Set MAVEN_HOME and PATH
Environment Variables โ System variables โ New:
MAVEN_HOME = C:\Program Files\Apache\maven
Then edit Path โ New โ %MAVEN_HOME%\bin
Install on Mac (Homebrew)
Install on Ubuntu/Linux
Expected output:
Understanding Key Maven Commands
| Command | What it does |
|---|---|
mvn compile | Compiles your Java source code |
mvn test | Compiles and runs tests |
mvn package | Creates a JAR/WAR file |
mvn clean | Deletes the target/ folder |
mvn clean install | Clean + compile + test + package + install to local repo |
mvn spring-boot:run | Runs a Spring Boot application |
Generate a project
Navigate and build
Run the app
You should see: Hello World!
JVM (Java Virtual Machine) โ An abstract machine that executes Java bytecode. It is platform-specific (there's a JVM for Windows, Mac, Linux) but the bytecode it runs is platform-independent โ "Write Once, Run Anywhere."
JRE (Java Runtime Environment) โ JVM + the standard class libraries (like java.lang, java.util). Enough to run Java applications.
JDK (Java Development Kit) โ JRE + development tools: javac (compiler), javadoc, jar, jdb (debugger). Required to write and compile Java code.
As a developer you always install the JDK.
Maven is a build automation and dependency management tool for Java projects. It solves two main problems:
1. Dependency management โ You declare libraries (Spring, Hibernate, etc.) in pom.xml and Maven downloads them automatically from a central repository (Maven Central). No more manually downloading JARs.
2. Build lifecycle โ Maven defines standard phases: validate โ compile โ test โ package โ install โ deploy. One command (mvn clean install) does everything.
POM stands for Project Object Model. The pom.xml file is the heart of a Maven project. It contains:
- coordinates โ groupId, artifactId, version (GAV) โ uniquely identify the project
- dependencies โ libraries your project needs
- plugins โ tools that run during the build (like the Spring Boot plugin)
- properties โ configuration like Java version
Scopes control when a dependency is available in the classpath:
- compile (default) โ available in all phases. E.g., Spring Boot starter.
- test โ only during testing. E.g., JUnit, Mockito.
- provided โ available at compile time but provided by the runtime. E.g., servlet-api (the container provides it).
- runtime โ not needed at compile time but needed at runtime. E.g., JDBC driver.
mvn package compiles, tests, and creates the JAR/WAR file in the target/ directory โ but only for the current project.
mvn install does everything package does, plus copies the artifact to your local Maven repository (~/.m2/repository). This makes the artifact available as a dependency for other local projects.
In most cases for Spring Boot apps, you use mvn package to get the deployable JAR, or mvn spring-boot:run to run directly during development.
JAVA_HOME is an environment variable that points to the JDK installation directory. Many tools (Maven, Gradle, IDEs, app servers) rely on JAVA_HOME to find the JDK they should use.
If JAVA_HOME is not set or points to the wrong version, tools may fail or use an unexpected Java version. Always verify that echo %JAVA_HOME% (Windows) or echo $JAVA_HOME (Mac/Linux) shows the correct JDK path.