Java Visual Studio Code

Visual Studio Code provides many features as a Java language editor. You can also install VS Code extensions to add more features for Java development.

The most common way is to set JAVAHOME environment variable to the install location of the JDK while you can also use java.home setting in Visual Studio Code settings (workspace or user settings) to configure it just for the editor. I described the installation/setup steps below. It is mainly based on the Visual Studio Code tutorial for Java.

Tip: To learn how to install and manage your extensions, refer to the extension documentation.

Thanks to the great Java community around VS Code, you can search for a large number of Java extensions easily within VS Code:

  1. Go to the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
  2. Filter the extensions list by typing 'java'.
  1. Testing Java with Visual Studio Code. Testing Java in Visual Studio Code is enabled by the Java Test Runner extension. It's a lightweight extension to run and debug Java test cases. The extension supports the following test frameworks: JUnit 4 (v4.8.0+) JUnit 5 (v5.1.0+) TestNG (v6.8.0+).
  2. Java on Visual Studio Code Update – February 2021. March 14th, 2021. Welcome to the February edition of VS Code update for Java. Spring is approaching.
  3. Visual Studio IntelliCode. The Visual Studio IntelliCode extension provides AI-assisted development features for Python, TypeScript/JavaScript and Java developers in Visual Studio Code, with insights based on understanding your code context combined with machine learning. You'll need Visual Studio Code October 2018 Release 1.29.1 or later to.

Recommended extensions

To help set up Java on VS Code, there is the Microsoft Java Extension Pack, which contains these popular extensions:

There are also great extensions provided by Pivotal and Microsoft for Spring Boot development, including:

Popular extensions from the community

Azure vsts agent. Thanks to the great Java community around VS Code, there are many great community-created extensions as well. You can search for more Java extensions easily within the VS Code:

  1. Go to the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
  2. Filter the extensions list by typing 'java'.

Here are a few useful extensions:

Java visual studio code hello world

We also appreciate contributions to any of our existing extensions and we hope you'll create new Java extensions if you don't find what you're looking for in the Marketplace. We're especially looking for help in areas such as support for Gradle and other Java application servers.

Recommended extensions with great Java support

We'd also like to recommend a couple of other extensions we believe are great to make VS Code even better for Java developers.

  1. Live Share is a great tool to use when you need to collaborate with someone else on the same code base.
  2. The Remote Development extensions let you use VS Code to access a container, a remote machine, or the Windows Subsystem for Linux.

Extension for container development

You can use Docker extension to build docker images and work with image registries.

Kubernetes extension provides an explorer view to manage clusters and the nodes inside. It also provides advanced syntax support for editing Kubernetes manifest files.

Recommended extensions for cloud (Azure) development

Team development

  • The Azure Repos extension makes it easy to connect to your Azure DevOps Servers, allowing you to easily monitor builds, pull requests, and work items for your TFVC or Git source repositories.

Internet of Things

  • The Azure IoT Toolkit for VS Code makes it easy to develop and connect your IoT applications to Azure. With this extension, you can interact with Azure IoT Hub, manage devices connected to Azure IoT Hub, and develop with code snippets for Azure IoT Hub.

General tools

  • The Azure Tools Extension Pack provides a rich set of extensions that makes it easy to discover and interact with Azure services to power your applications.

  • The Azure Resource Manager Tools provide a rich editing experience for Azure Resource Manager deployment templates and template language expressions. For example, IntelliSense for TLE function names, parameter references, signature help, Go to Definition, Peek Definition, and Peek References as well as Errors and Warnings, making it quick and easy to author Azure Resource Manager templates in VS Code.

Visit Azure Extensions to find more Azure extensions.

Visual Studio Code is an ideal lightweight development environment for Spring Boot application developers and there are several useful VS Code extensions including:

If you run into any issues when using the features below, you can contact us by clicking the Report an issue button below.

Prerequisites

A working Java environment with essential extensions installed is needed, including:

  • Java Development Kit (JDK), version 11 or later.
  • Apache Maven, version 3.0 or later.

For more details, please refer to Java Tutorial

Note: More information about JDK can be found at supported Java versions.

Create the project

The Spring Initializr extension allows you to search for dependencies and generate new Spring Boot projects.

To install, launch VS Code and from the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)), search for vscode-spring-initializr.

Once you have the extension installed, open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and type Spring Initializr to start generating a Maven or Gradle project and then follow the wizard.

Edit the project

The Spring Initializr extension allows you to edit dependencies after generating a new Spring Boot project.

Navigate to your pom.xml file and right-click to select Edit starters. The Command Palette will show the dependencies you already have beginning with a . You can search for other dependencies you want to add to your project. Or you can click on the existing dependencies to remove them.

Develop the application

The Spring Boot Tools extension includes rich language support for working with Spring Boot application.properties, application.yml, and .java files.

The extension supports quick navigate through source code, smart code completions, quick access to running apps, live application information, and code templates. Similar code completion and validation features are also available for .properties and .yml files.

Code

Run the application

Java Visual Studio Code For Mac

In addition to click F5 to run your application, there's another convenient extension Spring Boot Dashboard with which you can view and manage all available Spring Boot projects in your workspace as well as quickly start, stop, or debug your project.

Java With Visual Studio Code

Next steps

Java Visual Studio Code Install

  • To deploy your web app, see the Deploy a Java Application to Azure tutorial.
  • To containerize a web app and deploy as a Docker container, check out the Working with Docker.
  • To learn more about Java Debugging features, see Java Debugging Tutorial.