Level: Beginner
Time: ~60 minutes
Learning Objectives
- Install JDK 17+ and verify the installation
- Choose and set up a build tool (Maven or Gradle)
- Use Spring Initializr to generate a project
- Run the generated app from IDE and command line
2.1 Java Development Kit (JDK)
Requirement
- Spring Boot 3.x: Java 17 minimum
- Spring Boot 4.x: Java 17+ (supports up to Java 25)
Install JDK
Option A: Eclipse Temurin (recommended)
- Download: adoptium.net
- Choose JDK 17 or 21 LTS
Option B: Oracle JDK
- Download from Oracle Java
Option C: SDKMAN (macOS/Linux)
sdk install java 21.0.1-tem
sdk use java 21.0.1-tem
Verify
java -version
javac -version
You should see version 17 or higher.
2.2 Build Tools
Spring Boot works with Maven or Gradle. You only need one.
Maven
- Install: maven.apache.org or use the wrapper (
mvnw) included by Initializr - Verify:
mvn -v
Gradle
- Install: gradle.org or use the wrapper (
gradlew) from Initializr - Verify:
./gradlew --versionorgradle --version
Tip: Prefer the wrapper (mvnw/gradlew) so students use the same version without installing Maven/Gradle globally.
2.3 Spring Initializr
start.spring.io generates a ready-to-run Spring Boot project.
Steps
- Open https://start.spring.io
- Project: Maven or Gradle
- Language: Java (or Kotlin)
- Spring Boot: Latest 3.x (e.g. 3.2.x) or 4.x
- Metadata:
- Group:
com.example(or your domain) - Artifact:demo- Name / Description: optional - Package name: usually same as Group - Packaging: Jar
- Java: 17 or 21
- Dependencies: Add: - Spring Web — for REST/MVC (we use this in the first app)
- Click Generate and download the ZIP
What You Get
pom.xml(Maven) orbuild.gradle(Gradle)src/main/java— main application and packagessrc/main/resources—application.properties, static, templatessrc/test/java— test skeleton- Wrapper scripts:
mvnw/mvnw.cmdorgradlew/gradlew.bat
2.4 IDE Setup
IntelliJ IDEA
- File → New → Project from Existing Sources and select the project folder, or open the
pom.xml/build.gradle - JDK: Project Structure → Project → SDK = 17 or 21
- Run: open the main class (with
@SpringBootApplication) and click Run
Eclipse (with Spring Tools)
- Install Spring Tools 4 from the Eclipse Marketplace
- File → Import → Maven/Gradle → Existing Project
- Right-click project → Run As → Spring Boot App
VS Code
- Install Extension Pack for Java and Spring Boot Extension Pack
- Open folder; run from the main class or use the Spring Boot dashboard
2.5 Run the Application
From IDE
- Open the class that has
@SpringBootApplicationandmain(String[] args) - Run that class (e.g. green play button)
From Command Line
Maven:
./mvnw spring-boot:run
Gradle:
./gradlew bootRun
Build a JAR and Run
Maven:
./mvnw clean package
java -jar target/demo-0.0.1-SNAPSHOT.jar
Gradle:
./gradlew clean bootJar
java -jar build/libs/demo-0.0.1-SNAPSHOT.jar
Then open http://localhost:8080. The template project may show a Whitelabel error page until you add a controller — that’s expected.
2.6 Troubleshooting
| Issue | Check |
|---|---|
java: command not found |
JDK not installed or not on PATH |
| Wrong Java version | JAVA_HOME and java -version |
| Port 8080 in use | Change server.port in application.properties or stop the other process |
| Maven/Gradle not found | Use wrapper: ./mvnw or ./gradlew |
Summary
- Install JDK 17+ and a build tool (or use wrappers).
- Use Spring Initializr to create a project with Spring Web.
- Run with IDE or
./mvnw spring-boot:run/./gradlew bootRun. - Build a JAR with
package/bootJarand run it withjava -jar.
Exercises
- Generate a project from start.spring.io with Spring Web and run it; confirm it starts on port 8080.
- Change the server port to 9090 via
application.propertiesand run again. - Build the JAR and run it from the command line without the IDE.