Spring Visual Studio Code



  1. Visual Studio Code Spring Tools
  2. Visual Studio Code For Windows
  3. Visual Studio Code Spring Boot App
  4. Spring Boot Visual Studio Code Maven

Unlike JavaScript, Java code needs to be compiled so it wont work out of the box with visual studio code since it's just a glorified text editor. There are however multiple tools to accommodate for this, and the folks at VS code have a nice guide for setting you up - https://code.visualstudio.com/docs/java/java-spring-boot. Visual Studio Code Introduction. Visual Studio Code (VS Code) is an open source text editor developed by Microsoft and is free to use. It's known for being relatively lightweight while also incorporating key features found in modern IDE's such as Git integration and an extensive debugger.

This tutorial shows you how to write and run Hello World program in Java with Visual Studio Code. It also covers a few advanced features, which you can explore by reading other documents in this section.

For an overview of the features available for Java in VS Code, see Java Language Overview

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

Setting up VS Code for Java development

Coding Pack for Java

Visual studio or visual code

To help you set up quickly, you can install the Coding Pack for Java, which includes VS Code, the Java Development Kit (JDK), and essential Java extensions. The Coding Pack can be used as a clean installation, or to update or repair an existing development environment.

Install the Coding Pack for Java - macOS

Note: The Coding Pack for Java is only available for Windows and macOS. For other operating systems, you will need to manually install a JDK, VS Code, and Java extensions.

Installing extensions

If you are an existing VS Code user, you can also add Java support by installing Java Extension Pack, which includes these extensions:

The Java Extension Pack provides a Quick Start guide and tips for code editing and debugging. It also has a FAQ that answers some frequently asked questions. Use the command Java: Getting Started from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) to launch the guide.

You can also install extensions separately. The Extension Guide is provided to help you. You can launch the guide with the Java: Extension Guide command.

For this tutorial, the only required extensions are:

Settings for the JDK

Supported Java versions

The supported version for running the VS Code for Java extension and the supported version for your projects are two separate runtimes. To run VS Code for Java, Java SE 11 or above version is required; for projects, VS Code for Java supports projects with version 1.5 or above. For more details, refer to Configure JDK.

Using Java runtime configuration wizard

To help you configure correctly, we provide a runtime configuration wizard. You can launch the wizard by opening the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and typing the command Java: Configure Java Runtime, which will display the configuration user interface below.

Note: To configure multiple JDKs, see Configure JDK. To enable Java preview features, see How can I use VS Code with new Java versions

Visual

Using VS Code settings

Alternatively, you can configure JDK settings using the VS Code Settings editor. A common way to do this is setting the value of the JAVA_HOME system environment variable to the install location of the JDK, for example, C:Program FilesJavajdk-13.0.2. Or if you want to configure only VS Code to use the JDK, use the java.home setting in VS Code's User or Workspace settings.

Installing a Java Development Kit (JDK)

When you need install a JDK, we recommend you to consider installing from one of these sources:

Creating a source code file

Create a folder for your Java program and open the folder with VS Code. Then in VS Code, create a new file and save it with the name Hello.java. When you open that file, the Java Language Server automatically starts loading, and you should see a loading icon on the right side of the Status Bar. After it finishes loading, you will see a thumbs-up icon.

Note: If you open a Java file in VS Code without opening its folder, the Java Language Server might not work properly.

VS Code will also try to figure out the correct package for the new type and fill the new file from a template. See Create new file.

You can also create a Java project using the Java: Create Java Project command. Bring up the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and then type java to search for this command. After selecting the command, you will be prompted for the location and name of the project. You can also choose your build tool from this command.

Visual Studio Code also supports more complex Java projects, see Project Management.

Editing source code

You can use code snippets to scaffold your classes and methods. VS Code also provides IntelliSense for code completion, and various refactor methods.

To learn more about editing Java, see Java Editing.

Running and debugging your program

To run and debug Java code, set a breakpoint, then either press F5 on your keyboard or use the Run > Start Debugging menu item. You can also use the Run|Debug CodeLens options in the editor. After the code compiles, you can see all your variables and threads in the Run view.

The debugger also supports advanced features such as Hot Code replacement and conditional breakpoints.

For more information, see Java Debugging.

More features

The editor also has much more capability for your Java workload.

  • Editing Java explains how to navigate and edit Java in more details
  • Debugging illustrates all the key features of the Java Debugger
  • Testing provides comprehensive support for JUnit and TestNG framework
  • Java Project Management shows you how to use a project view and work with Maven
  • Spring Boot and Tomcat and Jetty demonstrate great framework support
  • Java Web Apps shows how to work with Java Web App in VS Code

Introduction

Spring

Visual Studio Code (VS Code) is an open source text editor developed by Microsoft and is free to use.It's known for being relatively lightweight while also incorporating key featuresfound in modern IDE's such as Git integration and an extensive debugger. This makesVS Code great for anything from simple Python scripting to denser software engineeringprojects.

Getting VS Code on your own computer

Visit VS Code's website and follow theinstructions to install it on your computer.

Example: welcome.py

By now, you should have VS Code installed. You have the optionof either finding the application or opening it up from the terminal.Recall from Lab 0 that you can open a terminal on the schoolcomputers by pressing Ctrl-Alt-t.

Let's first create and navigate to a directory called example, usingthe UNIX commands you learned in Lab 0:

Opening files

Now let's open up VS Code!

For Mac users, you'll most likely find VS Code in Applications.

Visual Studio Code Spring Tools

For Ubuntu users, you'll most likely find VS Code by putting itin the search bar.

For Windows users, you'll most likely find VS Code in Program Files.

You can also open VS Code in your current working directory via command line:

VS Code will open up to a welcome page. Open the explorer (page icon in the top leftcorner) then click EXAMPLE. To create a new file, either right click below EXAMPLEand select 'New File' or click the page icon with a plus in the corner. Let's name ourfile welcome.py. A pop-up will appear in the bottom right corner prompting you to installthe Python extension. We'll talk more about extensions later, but just install thePython extension for now, and ignore any other pop-ups that may appear. Now, we can begin programming!

Visual Studio Code For Windows

Editing files

Now we have VS Code open, we can begin writing our first Python file.We'll be writing a short program that prints out a welcome message whenexecuted. Don't worry, we don't expect you to know any Python yet! Allyou have to do is type in the following:

Once you've finished typing, VS Code should look something like this:

To save, you can just hit Ctrl-s (cmd-s on Mac) and the white dot by the file name should disappear.

Running Python

Back in our terminal, we're currently in our example directory.Let's play around with our code. In the terminal, start by typing

This command does the following:

  1. python3 is the command that starts Python
  2. The -i flag tells Python to start in interactive mode, which allows you to type in Python commands from your terminal
  3. welcome.py is the name of the Python file we want to run

Notice that the Python interpreter says >>>. This means Python isready to take a command.

Recall that we defined a function called welcome. Let's see what itdoes! Type in the following:

Python will then print out

Our code works! Feel free to try it out with your own name. Ok, now let's close Python by typing in

There are a couple of ways to exit Python. You can type in exit()or quit(). On MacOS and Linux, you can also type in Ctrl-d (thisdoesn't work on Windows).

Congratulations, you've edited your first file in VS Code!

Keyboard Shortcuts

VS Code has many, many keyboard shortcuts. Here are a few usefulones! (for Mac users, replace all the Ctrl sequences with cmd)

  • Ctrl-` : open an integrated terminal in VS Code
  • Ctrl-s : saves the current file
  • Ctrl-x : cuts the entire line your cursor is on
  • Ctrl-v : pastes the entire line you cut in the line above your cursor OR pastes the selected text in place
  • Ctrl-z : undo
  • Ctrl-shift-z : redo
  • tab : indent a line or a group of lines
  • shift-tab : dedent a line or a group of lines
  • Ctrl-d : highlights the current word. For every Ctrl-d you type after this first word, it will highlight every next instance of the word. This allows you to easily rename variables with multiple cursors! (Play around with this one, it's fun and very practical!)
  • Ctrl-tab : moves you to the next tab (Ctrl on Mac as well)
  • Ctrl-shift-tab : moves you to the previous tab (Ctrl on Mac as well)
  • Ctrl-f : search for a word
  • Ctrl-shift-f : searches through all tabs

Extensions

Extensions allow you to customize your text editor. They are pieces of softwarewritten by people like you and me or companies to improve everyone's quality of life.Extensions can do anything ranging from changing the color scheme, to allowing youto control Spotify while you code, to letting you share your workspace in realtime with your friends (❌ not on class assignments though ❌)! Hereis the documentation regarding extensions, but feel free to browse on your own by hitting Ctrl+shift+x.

This guide only scratches the surface of VS Code'sfunctionality. Remember, if there's something you wish VS Code coulddo, it probably can. Just Google it!

Visual Studio Code Spring Boot App

Pair Programming

You can pair program in VSCode using the Live Share extension.

Spring Boot Visual Studio Code Maven

Once you and your partner both have the extension installed, you'll need to start a new Live Share session and then explicitly share your code and terminal with each other. See the instructions on the download page for more details on sharing and joining sessions.