How to Set Up Java, Maven, and Spring Boot in Cursor: A Step‑by‑Step Guide
This guide walks you through configuring JDK and Maven, installing essential VS Code extensions for Java development, setting up MySQL, creating a Spring Boot project with Maven, and running it using the Cursor IDE, including tips for troubleshooting common version and configuration errors.
1. Configure JDK and Maven
The Cursor IDE automatically reads the JAVA_HOME and MAVEN_HOME environment variables. If they are not set, it falls back to the default path ~/.m2/settings.xml. You can also manually specify the locations by opening Preferences: Open User Settings (JSON) (Ctrl+Shift+P) and adding the appropriate entries, then reload the IDE.
Example JSON configuration:
{
"java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home",
"java.configuration.maven.userSettings": "/Users/mengday/Softwares/apache-maven-3.9.10/conf/settings.xml"
}2. Install Common Extensions
2.1 Extension Pack for Java (required)
Search for extensions with Ctrl+Shift+X and install the following components:
Language Support for Java(TM) by Red Hat : provides syntax highlighting, intelligent code completion, diagnostics, formatting (Shift+Alt+F on Windows/Linux, Shift+Option+F on macOS), navigation, and refactoring.
Debugger for Java : lightweight debugger with breakpoints, variable inspection, call‑stack view, and step‑through execution.
Maven for Java : creates new Maven projects, manages dependencies, and runs Maven lifecycle goals such as clean, compile, and package.
Test Runner for Java : supports JUnit and TestNG, runs tests, and displays detailed logs.
Project Manager for Java : visual project explorer, quick switching between multiple Java projects, and import of local projects.
Gradle for Java : integrates Gradle tasks, dependency management, and build execution.
2.2 Spring Boot Extension Pack
Provides tools for creating, running, and debugging Spring Boot applications directly from the IDE.
2.3 Spring Initializr Java Support
Enables generation of Spring Boot starter projects with selected dependencies.
2.4 Switch2IDEA
Allows seamless switching between Cursor (for AI‑assisted coding) and IntelliJ IDEA (for debugging). Use Alt+Shift+O to jump to the corresponding file in IDEA and synchronize the cursor position.
2.5 MySQL Plugin
Install the MySQL extension to manage database connections, execute queries, and view results within the IDE.
3. Create a Spring Boot Project
Select project type: Spring Boot .
Choose build tool: Maven Project .
Select Spring Boot version: 3.5.3 .
Set language: Java .
Enter Maven coordinates (e.g., Group Id com.example, Artifact Id demo).
Package type: Jar .
JDK version: 21 .
Add common dependencies such as spring-boot-starter-web and lombok.
Confirm and create the project in a new folder.
4. Run the Spring Boot Project
When launching, you may encounter errors caused by mismatched Java or Spring Boot versions, or incorrect Maven settings. If an error occurs, open a new chat in Cursor (Ctrl+Shift+L) and ask “Project startup error, please resolve”. Cursor will suggest fixes and can apply them automatically.
5. First Hands‑On Experience
In the Cursor chat, type:
Create a HelloWorldController file with a REST API that returns the string "helloworld ai".After the AI generates the code, click Accept to insert it into your project.
This step demonstrates how AI assistance can accelerate routine coding tasks within the development workflow.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Software Product Manager
Daily updates of Xiaomi's latest AI internal materials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
