1. Set Up Your Local Spring Boot Development Environment
Goal
Set up a complete Java development environment and create your first Spring Boot application from scratch.
What you’ll learn:
- How to install and configure Java development tools
- When to use Spring Initializr for project generation
- Best practices for Spring Boot project structure
Prerequisites
Before starting, ensure you have:
- ✓ A computer with internet access
- ✓ Administrator/sudo privileges to install software
- ✓ Basic familiarity with command line/terminal
Exercise Steps
Overview
- Install Java Development Kit (JDK)
- Install Apache Maven
- Generate Spring Boot Project
- Explore Project Structure
- Run Your First Spring Boot Application
Step 1: Install Java Development Kit (JDK)
Install the Java Development Kit to compile and run Java applications. Spring Boot 3.x requires JDK 17 or later to take advantage of modern Java features and long-term support.
Download the JDK from one of these sources:
- Oracle JDK: https://www.oracle.com/java/technologies/downloads/
- Eclipse Temurin (recommended): https://adoptium.net/
Choose JDK version 21 (recommended LTS version)
Install the JDK for your operating system:
Windows Installation
- Download the
.msiinstaller from Eclipse Temurin - Run the installer executable
- Follow the installation wizard:
- Accept the license agreement
- Choose installation directory (default is recommended)
- Important: Check “Add to PATH” option
- Important: Check “Set JAVA_HOME variable” option
- Complete the installation by clicking Finish
- Restart your terminal/command prompt for PATH changes to take effect
macOS Installation
Option A: Using Homebrew (recommended)
Install Homebrew if not already installed: https://brew.sh
Run the following command:
brew install openjdk@21Link the JDK (follow the instructions displayed after installation):
sudo ln -sfn /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk
Option B: Manual Installation
- Download the
.pkginstaller from Eclipse Temurin - Run the installer package
- Follow the installation wizard prompts
- Complete the installation
Linux Installation
Ubuntu/Debian:
sudo apt update sudo apt install openjdk-21-jdkFedora/RHEL/CentOS:
sudo dnf install java-21-openjdk-develArch Linux:
sudo pacman -S jdk21-openjdk- Download the
Verify the installation by opening a terminal and running:
java -versionExpected output should show Java 21 or later:
openjdk version "21.0.x" 2024-xx-xx
ℹ Concept Deep Dive
The JDK (Java Development Kit) includes the Java compiler, runtime environment, and development tools. LTS (Long-Term Support) versions like 17, 21, and 25 receive updates and security patches for several years, making them ideal for production applications. Spring Boot 3.x requires Java 17 as the minimum version and supports up to Java 25. Java 21 is recommended for its stability and widespread adoption.
⚠ Common Mistakes
- Installing JRE (Java Runtime Environment) instead of JDK - JRE cannot compile Java code
- Not setting JAVA_HOME environment variable on some systems
- Installing a JDK version older than 17 won’t work with Spring Boot 3.x
✓ Quick check: The
java -versioncommand displays version 21 or higher
Step 2: Install Apache Maven
Install Maven to manage dependencies and build your Spring Boot application. Maven automates the build process and downloads required libraries automatically.
Install Maven for your operating system:
Windows Installation
Download Maven 3.9.11 from: https://maven.apache.org/download.cgi
- Select
apache-maven-3.9.11-bin.zip
- Select
Extract the archive to a directory (e.g.,
C:\Program Files\Apache\maven)Set environment variables:
- Open System Properties → Environment Variables
- Add new system variable:
- Variable name:
MAVEN_HOME - Variable value:
C:\Program Files\Apache\maven(your Maven directory)
- Variable name:
- Edit the
Pathsystem variable:- Add new entry:
%MAVEN_HOME%\bin
- Add new entry:
Restart your terminal/command prompt for changes to take effect
macOS Installation
Option A: Using Homebrew (recommended)
Install Maven with a single command:
brew install mavenThis automatically installs the latest version and configures the PATH.
Option B: Manual Installation
Download Maven 3.9.11 from: https://maven.apache.org/download.cgi
- Select
apache-maven-3.9.11-bin.tar.gz
- Select
Extract to
/opt:sudo tar -xzvf apache-maven-3.9.11-bin.tar.gz -C /optAdd Maven to your shell profile (
~/.zshrcfor zsh or~/.bash_profilefor bash):export M2_HOME=/opt/apache-maven-3.9.11 export PATH=$M2_HOME/bin:$PATHReload your shell configuration:
source ~/.zshrc # or source ~/.bash_profile
Linux Installation
Option A: Using Package Manager (if available)
Ubuntu/Debian:
sudo apt update sudo apt install mavenFedora/RHEL/CentOS:
sudo dnf install mavenOption B: Manual Installation (latest version)
Download Maven 3.9.11:
wget https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gzExtract to
/opt:sudo tar -xzvf apache-maven-3.9.11-bin.tar.gz -C /optCreate symbolic link:
sudo ln -s /opt/apache-maven-3.9.11 /opt/mavenAdd Maven to PATH by editing
/etc/profile.d/maven.sh:sudo nano /etc/profile.d/maven.shAdd these lines:
export M2_HOME=/opt/maven export PATH=$M2_HOME/bin:$PATHMake the script executable and load it:
sudo chmod +x /etc/profile.d/maven.sh source /etc/profile.d/maven.sh
Verify the installation:
mvn -versionExpected output:
Apache Maven 3.9.11 Maven home: /path/to/maven Java version: 21.0.x
ℹ Concept Deep Dive
Maven is a build automation tool that manages project dependencies, compiles code, runs tests, and packages applications. Spring Boot projects include a Maven Wrapper (
mvnw), which means you can skip this step if you prefer - the wrapper will download Maven automatically when you first run it.⚠ Common Mistakes
- Forgetting to add Maven to PATH means you can’t run
mvnfrom any directory- Maven requires JAVA_HOME to be set correctly to find the JDK - it should point to JDK 21
- Not restarting the terminal after PATH changes means the new settings won’t take effect
- Using package manager Maven might install an older version - check the version after installation
✓ Quick check: Running
mvn -versionshows Maven 3.9.x and displays Java version 21.0.x
Step 3: Generate Spring Boot Project
Use Spring Initializr to create a new Spring Boot project with all necessary configuration files. This online tool generates a complete project structure following Spring Boot best practices.
Option A: Using Web Interface (Recommended)
Navigate to https://start.spring.io in your web browser
Configure the project settings in the left panel:
Project:
- Select: Maven
Language:
- Select: Java
Spring Boot:
- Select: 3.5.7 (the currently selected stable version)
Project Metadata:
- Group:
com.jin - Artifact:
hellojava - Name:
HelloJava - Description:
Spring Boot Demo Application for Azure - Package name:
com.jin.hellojava
Packaging:
- Select: Jar (should be selected by default)
Configuration:
- Keep: Properties (default)
Java:
- Select: 21 (change from 17 if needed)
Add dependencies by clicking “ADD DEPENDENCIES…” button in the top right:
- Search for and add: Spring Web
- This enables building web applications and REST APIs
Click the “GENERATE” button at the bottom to download
hellojava.zipNavigate to your project root directory in terminal:
cd /Users/lasse/Developer/JIN_Development/HelloJavaMove the downloaded zip file to the current directory if needed
Option B: Using curl (Command Line)
Navigate to your project root directory in terminal:
cd /Users/lasse/Developer/JIN_Development/HelloJavaGenerate and download the project directly using curl:
curl https://start.spring.io/starter.zip \ -d type=maven-project \ -d language=java \ -d bootVersion=3.5.7 \ -d baseDir=hellojava \ -d groupId=com.jin \ -d artifactId=hellojava \ -d name=HelloJava \ -d description='Spring Boot Demo Application for Azure' \ -d packageName=com.jin.hellojava \ -d packaging=jar \ -d javaVersion=21 \ -d dependencies=web \ -o hellojava.zipThis creates
hellojava.zipdirectly in your current directory with all the correct settings.
Extract the zip file and move contents to project root (to preserve hidden files):
On Mac/Linux:
unzip hellojava.zip -d . && mv hellojava/{*,.*} . 2>/dev/null; rmdir hellojava && rm hellojava.zipOn Windows (PowerShell):
Expand-Archive -Path hellojava.zip -DestinationPath . Get-ChildItem -Path hellojava -Force | Move-Item -Destination . -Force Remove-Item -Recurse -Force hellojava Remove-Item hellojava.zipThis extracts the zip, moves all files (including hidden files) to the project root, removes the empty directory, and deletes the zip file
ℹ Concept Deep Dive
Spring Initializr generates a complete Maven project with
pom.xml(dependency configuration), main application class, test class, and configuration files. The Spring Web dependency includes embedded Tomcat server and Spring MVC framework, allowing you to build web applications without installing a separate application server. The Maven Wrapper files (mvnwandmvnw.cmd) allow running Maven commands even without Maven installed.⚠ Common Mistakes
- Wrong group/package naming prevents Spring Boot from finding components
- Choosing “War” packaging instead of “Jar” requires additional servlet container setup
- Forgetting to add Spring Web dependency means no web capabilities
✓ Quick check: The extracted directory contains
pom.xml,mvnw, andsrcfolder
Step 4: Explore Project Structure
Understand the standard Spring Boot project layout to know where to place your code and resources. This conventional structure helps developers quickly navigate any Spring Boot project.
Open the project folder in your preferred text editor or IDE
Review the key directories and files:
project-root/ ├── .mvn/ │ └── wrapper/ │ └── maven-wrapper.properties ├── src/ │ ├── main/ │ │ ├── java/com/jin/hellojava/ │ │ │ └── HelloJavaApplication.java │ │ └── resources/ │ │ ├── application.properties │ │ ├── static/ │ │ └── templates/ │ └── test/ │ └── java/com/jin/hellojava/ │ └── HelloJavaApplicationTests.java ├── .gitattributes (Git line ending configuration) ├── .gitignore (Git ignore rules) ├── HELP.md (Spring Initializr help documentation) ├── mvnw (Maven wrapper for Mac/Linux) ├── mvnw.cmd (Maven wrapper for Windows) └── pom.xml (Maven project configuration)Examine the main application class at
src/main/java/com/jin/hellojava/HelloJavaApplication.java:src/main/java/com/jin/hellojava/HelloJavaApplication.javapackage com.jin.hellojava; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HelloJavaApplication { public static void main(String[] args) { SpringApplication.run(HelloJavaApplication.class, args); } }
ℹ Concept Deep Dive
The
src/main/javadirectory contains your application code. Thesrc/main/resourcesdirectory holds configuration files, static assets (CSS, JavaScript), and templates. The@SpringBootApplicationannotation enables auto-configuration, component scanning, and configuration properties. Thepom.xmlfile defines project dependencies and build configuration. Maven Wrapper scripts ensure everyone uses the same Maven version - usemvnwon Mac/Linux ormvnw.cmdon Windows. The wrapper files (mvnw,mvnw.cmd, and.mvn/wrapper/) should be committed to version control so others can build the project without installing Maven.⚠ Common Mistakes
- Placing classes outside the main package prevents Spring Boot’s component scanning
- Modifying the main application class name without updating configuration
- Confusing
resources(for config/assets) withjava(for code)- Adding Maven wrapper files to
.gitignore- they should be committed✓ Quick check: All standard directories exist and the main application class has
@SpringBootApplicationannotation
Step 5: Run Your First Spring Boot Application
Start the Spring Boot application to verify everything is configured correctly. Even without adding custom code, Spring Boot will start an embedded web server.
Run the application using Maven wrapper:
./mvnw spring-boot:runOn Windows, use:
mvnw.cmd spring-boot:runWait for the startup to complete. Look for this message in the console:
Started HelloJavaApplication in X.XXX secondsStop the application by pressing
Ctrl+Cin the terminal
ℹ Concept Deep Dive
Spring Boot starts an embedded Tomcat server on port 8080 by default. The
spring-boot:runMaven goal compiles your code and starts the application in development mode with automatic classpath setup. The startup time includes initializing the Spring context, auto-configuration, and starting the embedded server. You haven’t created any endpoints yet, but the application successfully starts and is ready to handle HTTP requests.⚠ Common Mistakes
- Port 8080 already in use: change the port in
application.propertieswithserver.port=8081- Build failures: ensure JDK 17+ is being used by Maven
- Permission denied on
mvnw: runchmod +x mvnwon Linux/Mac✓ Quick check: Application starts successfully and displays “Started HelloJavaApplication” message
✓ Success indicators:
- Application starts without errors
- Console shows Spring Boot banner and startup logs
- Application can be stopped cleanly with Ctrl+C
✓ Final verification checklist:
- ☐ JDK 21 installed and verified
- ☐ Maven installed or wrapper scripts work
- ☐ Spring Boot project generated and extracted
- ☐ Project structure matches expected layout
- ☐ Application starts and stops successfully
Common Issues
If you encounter problems:
“java: command not found”: JDK not installed or not in PATH. Reinstall JDK and verify PATH configuration
“mvnw: Permission denied”: Run
chmod +x mvnwon Linux/Mac to make the wrapper executable“Port 8080 already in use”: Another application is using the port. Create
src/main/resources/application.propertiesand addserver.port=8081“UnsupportedClassVersionError”: Java version mismatch. Verify JDK 21 is installed and Maven is using it
Build errors: Delete the
.m2/repositoryfolder in your home directory and rerun to download fresh dependenciesStill stuck? Check the full error stack trace in the console output for specific issues
Summary
You’ve successfully set up a Spring Boot development environment which:
- ✓ Includes all necessary tools (JDK, Maven)
- ✓ Generated a proper Spring Boot project structure
- ✓ Runs a working Spring Boot application
Key takeaway: Spring Boot’s auto-configuration and embedded server make it incredibly fast to start building web applications. No complex server setup or XML configuration required - just download the JDK, generate a project, and run. This streamlined development experience is why Spring Boot is the most popular Java framework for modern applications.
Going Deeper (Optional)
Want to explore more?
- Install an IDE like IntelliJ IDEA Community Edition or Eclipse
- Explore the generated
pom.xmlto understand Maven dependencies- Try the command-line alternative: generate projects using curl to Spring Initializr API
- Add Spring Boot DevTools dependency for automatic restart on code changes
- Explore Spring Boot Actuator for production-ready features
Done! 🎉
Excellent work! You’ve set up a complete Java development environment and created your first Spring Boot application. This foundation will support all your future Spring Boot development. You’re now ready to add controllers, services, and build real applications.