SoFunction
Updated on 2025-04-06

Detailed steps for running Java SpringBoot in VS Code

1. Install the necessary extensions

  • Java Extension Pack: Includes all required Java extensions, such asLanguage Support for Java(TM) by Red HatandDebugger for Java
  • Spring Boot Extension Pack:includeSpring Boot ExtensionandSpring Boot Dashboard

2. Configure the environment

Make sure the following software is installed:

  • Java Development Kit (JDK): It is recommended to use JDK 11 or higher.
  • Maven: Used to build and manage Spring Boot projects.
  • Spring Boot CLI (optional): Used to quickly create Spring Boot projects.

3. Create or import Spring Boot project

Create a new project using Spring Initializr

  • Open the command panel(according toCtrl+Shift+PorCmd+Shift+P)。
  • InputSpring Initializr: Generate a Maven ProjectAnd select this option.
  • Follow the prompts to select the configuration of the project, such as Group, Artifact, Dependencies, etc.
  • Select the project generation location and click "Generate".
  • VSCode will prompt you to open the generated project.

Import existing projects

  • Drag the project folder directly into the VSCode window.
  • VSCode will automatically detect and recommend that you install the required extensions (if not already installed).

4. Configure VSCode

Configure the debugging environment

  • Open the debug view(Click on the bug icon on the sidebar or pressCtrl+Shift+D)。
  • Clickcreate a file, and then selectJava
  • VSCode will generate aFiles, usually located in.vscodeIn the folder, the content is as follows:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "java",
                "name": "Debug (Launch) - Current File",
                "request": "launch",
                "mainClass": "${file}"
            },
            {
                "type": "java",
                "name": "Debug (Attach)",
                "request": "attach",
                "hostName": "localhost",
                "port": 5005
            },
            {
                "type": "java",
                "name": "Debug (Launch) - MyApp",
                "request": "launch",
                "mainClass": "",
                "projectName": "my-app"
            }
        ]
    }
    
    WillmainClassandprojectNameModify to the actual value of your project.

5. Run and debug projects

Run via command line

  • Open the terminal(according toCtrl+orCmd+)。
  • Navigate to the project root directory.
  • Runmvn spring-boot:runCommand to start the Spring Boot application.

Run via Spring Boot Dashboard

  • Click the Spring Boot Dashboard on the sidebar.
  • Find your project in Spring Boot Dashboard.
  • Click the play button to run the project.

Run in debug mode

  • Set breakpoint: Click on the left side of the code line number to add a breakpoint.
  • Open the debug view (pressCtrl+Shift+D)。
  • Select the previously configuredDebug (Launch) - MyAppConfiguration.
  • Click the green Start button to start debugging.

6. Use Spring Boot Actuator (optional)

If your project contains Spring Boot Actuator, you can access the endpoint (such as/actuator/health) to monitor and manage applications.

7. Configure task automation (optional)

You can use VSCode's task system to automate the build and run steps:

  • Create.vscode/document.
  • Add the following configuration:
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Run Spring Boot",
                "type": "shell",
                "command": "mvn spring-boot:run",
                "group": "build",
                "problemMatcher": [],
                "detail": "Runs the Spring Boot application"
            }
        ]
    }
    
  • You can run this task through the Task Panel or shortcut keys.

8. Summary

The above is a complete guide on how to configure and run a Java Spring Boot project in VSCode. Installing the necessary extensions, configuring the debugging environment, and running and debugging Spring Boot applications through the command line or VSCode built-in tools can improve your development efficiency.

This is the end of this article about running Java SpringBoot projects in VS Code. For more related contents of running SpringBoot projects in VS Code, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!