Как писать на java в visual studio code
Перейти к содержимому

Как писать на java в visual studio code

  • автор:

Name already in use

vscode-docs / docs / languages / java.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

Java in Visual Studio Code

Support for Java in Visual Studio Code is provided through a wide range of extensions. Combined with the power of core VS Code, these extensions give you a lightweight and performant code editor that also supports many of the most common Java development techniques.

This article will give you an overview of different capabilities of Visual Studio Code for Java developers. For a quick walkthrough of editing, running, and debugging a Java program with Visual Studio Code, use the Java Getting Started Tutorial button below.

VS Code provides essential language features such as code completion, refactoring, linting, formatting, and code snippets along with convenient debugging and unit test support. VS Code also integrates with tooling and frameworks such as Maven, Tomcat, Jetty, and Spring Boot. Leveraging the power of Visual Studio Code, Java developers get an excellent tool for both quick code editing and also the full debugging and testing cycle. It’s a great choice for your Java work if you’re looking for a tool which:

  • Is fast, lightweight, free, and open source.
  • Supports many other languages, not just Java.
  • Helps start your Java journey without installing and learning a complex IDE.
  • Provides great microservices support including popular frameworks, container tooling, and cloud integration.
  • Offers team-based collaboration features such as Visual Studio Live Share.
  • Improves your productivity through IntelliSense and other code-aware editing features.

Install Visual Studio Code for Java

To help you set up quickly, we recommend you use the Coding Pack for Java, which is the bundle of VS Code, the Java Development Kit (JDK), and a collection of suggested extensions by Microsoft. The Coding Pack can also be used to fix an existing development environment.

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.

If you have already installed VS Code and want to add Java support to it, we recommend using the Extension Pack for Java, a collection of extensions suggested by Microsoft:

Install the Extension Pack for Java

Alternatively, you can add Java language support to VS Code by installing the popular Java extensions by yourself.

Download VS Code — If you haven’t downloaded VS Code yet, quickly install for your platform (Windows, macOS, Linux).

There are also other popular Java extensions you can pick for your own needs, including:

Thanks to the great Java community around VS Code, the list doesn’t end there. You can search for more Java extensions easily within VS Code:

  1. Go to the Extensions view ( kb(workbench.view.extensions) ).
  2. Filter the extensions list by typing «java».

This document describes some of the key features included in those Java extensions.

NOTE: If you are using VS Code on Windows and want to take advantage of the Windows Subsystem for Linux, see Developing in WSL.

Install a Java Development Kit (JDK)

A Java Development Kit (JDK) is a software development environment used for developing Java applications. In order to run Java within Visual Studio Code, you need to install a JDK. The Extension Pack for Java supports Java version 1.5 or above.

We recommend you to consider installing the JDK from one of these sources:

Note : If you have multiple JDKs installed and need to use a specific JDK version for your projects, see Configure Runtime for Projects. To enable Java preview features, see How can I use VS Code with new Java versions.

For developers new to Java or new to VS Code, we do provide some tips in our extensions. Once you’ve installed the Extension Pack for Java, you can see the tips using the Java: Tips for Beginners command from the Command Palette in VS Code.

Open the Command Palette ( kb(workbench.action.showCommands) ) and type «java tips» to select the command.

Java Getting Started

Working with Java source files

You can use VS Code to read, write, run, and debug Java source file(s) without creating a project. VS Code for Java supports two modes, lightweight and standard. Lightweight mode is ideal for scenarios that only deal with source file(s). If you want to work with a full-scale project, standard mode will be required. You can easily switch from lightweight mode to standard mode, when needed. To learn more, see Lightweight Mode.

Working with Java projects

There are three things you must understand to work with Java in VS Code:

  1. How does VS Code handle Workspaces?
  2. How does VS Code handle Java?
  3. How does VS Code handle Workspaces that contain Java?

VS Code Workspaces

In Visual Studio Code, a «Workspace» means a collection of one or more filesystem folders (and their children) and all of the VS Code configurations that take effect when that «Workspace» is open in VS Code. There are two kinds of «Workspaces» in VS Code, «folder workspaces» and «multi-root workspaces».

A «folder workspace» is presented by VS Code when you open a filesystem folder (directory) in VS Code.

A «multi-root workspace» can refer to multiple folders (directories) from disparate parts of the file system and VS Code displays the contents of the folder(s) of the workspace together in the File Explorer. To learn more, see Multi-root Workspaces.

Java projects in VS Code

In contrast to IDEs such as IntelliJ IDEA, NetBeans, or Eclipse, the concept of a «Java project» is provided entirely by extensions, and is not a core concept in the base VS Code. When working with «Java projects» in VS Code, you must have the necessary extensions installed to work with those project files.

For example, Maven, Eclipse, and Gradle Java projects are supported through Language Support for Java™ by Red Hat, by utilizing M2Eclipse, which provides Maven support, and Buildship, which provides Gradle support through the Eclipse JDT Language Server.

With Maven for Java, you can generate projects from Maven Archetypes, browse through all the Maven projects within your workspace, and execute Maven goals easily from an embedded explorer. Projects can also be created and managed with the Project Manager for Java extension.

Visual Studio Code also supports working with standalone Java files outside of a Java project, described in the Getting Started with Java tutorial.

VS Code Workspaces that contain Java projects

Assuming the necessary Java extensions are installed, opening a VS Code workspace that contains Java artifacts will cause those extensions to understand those artifacts and present options for working with them.

More details about Java project support can be found in Java Project Management in Visual Studio Code and Java Build Tools.

Java in Visual Studio Code also supports source code navigation features such as search for symbol, Peek Definition, and Go to Definition. The Spring Boot Tools extension provides enhanced navigation and code completion support for Spring Boot projects.

One of the key advantages of VS Code is speed. When you open your Java source file or folder, within a few seconds, with the help of Lightweight Mode, you will be able to navigate your code base with the Outline view, as well as commands such as Go to Definition and Go to Reference. This is especially useful when you open a project for the first time.

IntelliSense is a general term for language features, including intelligent code completion (in-context method and variable suggestions) across all your files and for both built-in and third-party modules. VS Code supports code completion and IntelliSense for Java through Language Support for Java™ by Red Hat. It also provides AI-assisted IntelliSense called IntelliCode by putting what you’re most likely to use at the top of your completion list.

Enhance completions with AI

GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.

Copilot extension in the VS Code Marketplace

GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++.

You can learn more about how to get started with Copilot in the Copilot documentation.

Visual Studio Code supports a wide range of popular Java code snippets to make you more productive, such as class/interface, syserr, sysout, if/else, try/catch, static main method. Using information from Java language server, it also provides a preview of the code snippet during the selection.

For example, typing «sout» or «sysout» will produce a code snippet for System.out.println() .
Similarly, typing «main» or «psvm» will generate a code snippet for public static void main(String[] args) <> .

We support a wide range of code snippet shortcuts and postfix completion features. To see the complete list, see Code Snippets. VS Code also supports a range of Refactoring and Linting features.

Code Snippet

Debugger for Java is a lightweight Java Debugger based on Java Debug Server. It works with Language Support for Java™ by Red Hat to allow users to debug Java code within Visual Studio Code.

Starting a debugging session is easy: click the Run|Debug button available at the CodeLens of your main() function, or press kb(workbench.action.debug.start) . The debugger will automatically generate the proper configuration for you.

Although it’s lightweight, the Java debugger supports advanced features such as expression evaluation, conditional breakpoints, and Hot Code Replace. For more debugging-related information, visit Java Debugging.

With the support from the Test Runner for Java extension, you can easily run, debug, and manage your JUnit and TestNG test cases.

For more about testing, read Testing Java.

Spring Boot, Tomcat, and Jetty

To further improve your Java productivity in VS Code, there are extensions for most popular frameworks and tools, such as Spring Boot, Tomcat, and Jetty, created by the community.

See Application Servers to learn more about support for Tomcat and Jetty, as well as other application servers with VS Code.

Spring Boot support is provided by Pivotal. There are also the Spring Initializr Java Support and Spring Boot Dashboard extensions provided by Microsoft, to further improve your experience with Spring Boot in Visual Studio Code.

See Spring Boot with VS Code to learn more about Spring Boot support in VS Code, and also Deploy to Azure Web Apps or Deploy to Azure Spring Apps to learn more about deploying Spring apps to Azure from VS Code.

Java in Visual Studio Code

Support for Java in Visual Studio Code is provided through a wide range of extensions. Combined with the power of core VS Code, these extensions give you a lightweight and performant code editor that also supports many of the most common Java development techniques.

This article will give you an overview of different capabilities of Visual Studio Code for Java developers. For a quick walkthrough of editing, running, and debugging a Java program with Visual Studio Code, use the Java Getting Started Tutorial button below.

Overview

VS Code provides essential language features such as code completion, refactoring, linting, formatting, and code snippets along with convenient debugging and unit test support. VS Code also integrates with tooling and frameworks such as Maven, Tomcat, Jetty, and Spring Boot. Leveraging the power of Visual Studio Code, Java developers get an excellent tool for both quick code editing and also the full debugging and testing cycle. It’s a great choice for your Java work if you’re looking for a tool which:

  • Is fast, lightweight, free, and open source.
  • Supports many other languages, not just Java.
  • Helps start your Java journey without installing and learning a complex IDE.
  • Provides great microservices support including popular frameworks, container tooling, and cloud integration.
  • Offers team-based collaboration features such as Visual Studio Live Share.
  • Improves your productivity through IntelliSense and other code-aware editing features.

Install Visual Studio Code for Java

To help you set up quickly, we recommend you use the Coding Pack for Java, which is the bundle of VS Code, the Java Development Kit (JDK), and a collection of suggested extensions by Microsoft. The Coding Pack can also be used to fix an existing development environment.

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.

If you have already installed VS Code and want to add Java support to it, we recommend using the Extension Pack for Java, a collection of extensions suggested by Microsoft:

Alternatively, you can add Java language support to VS Code by installing the popular Java extensions by yourself.

Download VS Code — If you haven’t downloaded VS Code yet, quickly install for your platform (Windows, macOS, Linux).

There are also other popular Java extensions you can pick for your own needs, including:

Thanks to the great Java community around VS Code, the list doesn’t end there. You can search for more 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".

This document describes some of the key features included in those Java extensions.

Getting started

NOTE: If you are using VS Code on Windows and want to take advantage of the Windows Subsystem for Linux, see Developing in WSL.

Install a Java Development Kit (JDK)

A Java Development Kit (JDK) is a software development environment used for developing Java applications. In order to run Java within Visual Studio Code, you need to install a JDK. The Extension Pack for Java supports Java version 1.5 or above.

We recommend you to consider installing the JDK from one of these sources:

Note: If you have multiple JDKs installed and need to use a specific JDK version for your projects, see Configure Runtime for Projects. To enable Java preview features, see How can I use VS Code with new Java versions.

For developers new to Java or new to VS Code, we do provide some tips in our extensions. Once you’ve installed the Extension Pack for Java, you can see the tips using the Java: Tips for Beginners command from the Command Palette in VS Code.

Open the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ) and type "java tips" to select the command.

Java Getting Started

Working with Java source files

You can use VS Code to read, write, run, and debug Java source file(s) without creating a project. VS Code for Java supports two modes, lightweight and standard. Lightweight mode is ideal for scenarios that only deal with source file(s). If you want to work with a full-scale project, standard mode will be required. You can easily switch from lightweight mode to standard mode, when needed. To learn more, see Lightweight Mode.

Working with Java projects

There are three things you must understand to work with Java in VS Code:

  1. How does VS Code handle Workspaces?
  2. How does VS Code handle Java?
  3. How does VS Code handle Workspaces that contain Java?

VS Code Workspaces

In Visual Studio Code, a "Workspace" means a collection of one or more filesystem folders (and their children) and all of the VS Code configurations that take effect when that "Workspace" is open in VS Code. There are two kinds of "Workspaces" in VS Code, "folder workspaces" and "multi-root workspaces".

A "folder workspace" is presented by VS Code when you open a filesystem folder (directory) in VS Code.

A "multi-root workspace" can refer to multiple folders (directories) from disparate parts of the file system and VS Code displays the contents of the folder(s) of the workspace together in the File Explorer. To learn more, see Multi-root Workspaces.

Java projects in VS Code

In contrast to IDEs such as IntelliJ IDEA, NetBeans, or Eclipse, the concept of a "Java project" is provided entirely by extensions, and is not a core concept in the base VS Code. When working with "Java projects" in VS Code, you must have the necessary extensions installed to work with those project files.

For example, Maven, Eclipse, and Gradle Java projects are supported through Language Support for Java™ by Red Hat, by utilizing M2Eclipse, which provides Maven support, and Buildship, which provides Gradle support through the Eclipse JDT Language Server.

With Maven for Java, you can generate projects from Maven Archetypes, browse through all the Maven projects within your workspace, and execute Maven goals easily from an embedded explorer. Projects can also be created and managed with the Project Manager for Java extension.

Visual Studio Code also supports working with standalone Java files outside of a Java project, described in the Getting Started with Java tutorial.

VS Code Workspaces that contain Java projects

Assuming the necessary Java extensions are installed, opening a VS Code workspace that contains Java artifacts will cause those extensions to understand those artifacts and present options for working with them.

More details about Java project support can be found in Java Project Management in Visual Studio Code and Java Build Tools.

Editing

Code Navigation

Java in Visual Studio Code also supports source code navigation features such as search for symbol, Peek Definition, and Go to Definition. The Spring Boot Tools extension provides enhanced navigation and code completion support for Spring Boot projects.

One of the key advantages of VS Code is speed. When you open your Java source file or folder, within a few seconds, with the help of Lightweight Mode, you will be able to navigate your code base with the Outline view, as well as commands such as Go to Definition and Go to Reference. This is especially useful when you open a project for the first time.

Code Completion

IntelliSense is a general term for language features, including intelligent code completion (in-context method and variable suggestions) across all your files and for both built-in and third-party modules. VS Code supports code completion and IntelliSense for Java through Language Support for Java™ by Red Hat. It also provides AI-assisted IntelliSense called IntelliCode by putting what you’re most likely to use at the top of your completion list.

Enhance completions with AI

GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.

Copilot extension in the VS Code Marketplace

GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++.

You can learn more about how to get started with Copilot in the Copilot documentation.

Code snippets

Visual Studio Code supports a wide range of popular Java code snippets to make you more productive, such as class/interface, syserr, sysout, if/else, try/catch, static main method. Using information from Java language server, it also provides a preview of the code snippet during the selection.

For example, typing "sout" or "sysout" will produce a code snippet for System.out.println() .
Similarly, typing "main" or "psvm" will generate a code snippet for public static void main(String[] args) <> .

We support a wide range of code snippet shortcuts and postfix completion features. To see the complete list, see Code Snippets. VS Code also supports a range of Refactoring and Linting features.

Code Snippet

Debugging

Debugger for Java is a lightweight Java Debugger based on Java Debug Server. It works with Language Support for Java™ by Red Hat to allow users to debug Java code within Visual Studio Code.

Starting a debugging session is easy: click the Run|Debug button available at the CodeLens of your main() function, or press F5 . The debugger will automatically generate the proper configuration for you.

Although it’s lightweight, the Java debugger supports advanced features such as expression evaluation, conditional breakpoints, and Hot Code Replace. For more debugging-related information, visit Java Debugging.

Testing

With the support from the Test Runner for Java extension, you can easily run, debug, and manage your JUnit and TestNG test cases.

For more about testing, read Testing Java.

Spring Boot, Tomcat, and Jetty

To further improve your Java productivity in VS Code, there are extensions for most popular frameworks and tools, such as Spring Boot, Tomcat, and Jetty, created by the community.

See Application Servers to learn more about support for Tomcat and Jetty, as well as other application servers with VS Code.

Spring Boot support is provided by Pivotal. There are also the Spring Initializr Java Support and Spring Boot Dashboard extensions provided by Microsoft, to further improve your experience with Spring Boot in Visual Studio Code.

See Spring Boot with VS Code to learn more about Spring Boot support in VS Code, and also Deploy to Azure Web Apps or Deploy to Azure Spring Apps to learn more about deploying Spring apps to Azure from VS Code.

Getting Started with Java in VS Code

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 entering an issue.

Setting up VS Code for Java development

Coding Pack for Java

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.

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 the Extension Pack for Java, which includes these extensions:

The Extension Pack for Java 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: Tips for Beginners from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ) to launch the guide.

Java Getting Started

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

For this tutorial, the only required extensions are:

Installing and setting up a Java Development Kit (JDK)

To use Java within Visual Studio Code, you need to install a Java Development Kit (JDK) on your local environment. JDK is a software development environment used for developing Java applications.

Supported Java versions

The Extension Pack for Java supports Java version 1.5 or above.

Note: To configure JDKs for your projects, see Configure Runtime for Projects. To enable Java preview features, see How can I use VS Code with new Java versions.

Installing a Java Development Kit (JDK)

If you have never installed a JDK before and need to install one, we recommend you to choose 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 language status item with a loading icon on the right side of the Status Bar showing the language status is busy. After it finishes loading, you can hover on the language status item and find the loading process has been finished successfully. You can also choose to pin the status item in the status bar.

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 option in the editor. After the code compiles, you can see all your variables and threads in the Run and Debug view.

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

For more information, see Java Debugging.

More features

The editor also has many more capabilities to assist with your Java workload.

How to Build a Java Application in Visual Studio Code in 2022

For years, Java development has been dominated by three leading IDEs: Eclipse, IntelliJ IDEA and NetBeans. But we have other suitable opportunities. Among many talented multilingual code editors, Visual Studio Code has proven to be an outstanding product with exceptional Java support. VS Code also provides world-class support for other technology stacks, including front-end JavaScript frameworks, Node.js, and Python.

Building a Java Application in Visual Studio Code in 2022

Should Visual Studio Code be your following Java IDE? This article describes using Visual Studio Code to create an enterprise Java back end with Spring and connect to the Svelte JavaScript front end.

Set up Spring Boot

To build with this tutorial, you must have Java and Maven installed. You will also need the latest version of the Visual Studio code for your system if you do not already have one. After that, it's easy to install.

Let's go straight to the new project. You plan to use Spring Initializer to create a Spring startup website program. First, open VS Code and click the extension icon in the top left corner. This is a great way to search for available plugins (and there are many). Type spring starts, and you will see the support extension for Java Spring Initializr. Install it as shown in Figure 1.

Figure 1. Installing the Spring Initializr extension

Once installed (it doesn't take long), you can use it from the command palette, which can be accessed by Ctrl-Shift-P (or View -> Main Menu Command Palette). When the command palette is open, enter "spring start", and you will see the newly installed command. Run it.

Let us now come to the master. You can accept most of the default settings, for example, Java; Java version 12; Artifact identifier "demo"; Group ID "com.InfoWorld"; Packaging "VASO"; and the rest. When adding dependencies, add Spring Boot Web and Spring DevTools. (You can add more dependencies later by right-clicking the POM file and selecting Add Starter.) You will also choose the project's location; select the appropriate location on your local drive.

Once the new project has been created and loaded into your workspace, you can open a command-line terminal by typing Ctrl-Shift or choosing Terminal -> New Terminal from the main menu.

Enter Spring Boot: run mvn on the terminal. The first time you do this, Maven will download your new dependencies. As soon as this is done, the development server is operational. To confirm this, open your browser and go to localhost: 8080. You will see a default "not found" page as we have not yet defined the routes, but it does confirm that the server is running.

You can quickly access the files by pressing Ctrl-Shift-P and typing "Demo" to see the DemoApplication.java file. Open it, and you will see a typical standalone spring launcher.

We are now installing a Java plugin that offers us many functions such as IntelliSense and context-based resource generation. Back in the extension menu, type in "Java Extension" and install the Java Extension Package. Finally, add the Spring Boot Extension Pack.

Now when you open the DemoApplication.java file, you will find that the VS code has a good run and debug commands directly in the source file.

Import the Java project

Here Visual Studio Code understands Java and asks, "This project contains Java. Do you want to import it?" Go ahead and choose Always. Once that's done, the VS code can be automatically updated for Java etc.

We add a REST controller. Open the file browser (top left corner), right-click / src / com / InfoWorld / demo and select New File. Name the file MyController.java. You will find that the VS code has ordered your class for you, as shown in list 1.

Listing 1. Java stub in VS Code

public class MyController <

Start by marking the class as @RestController. Please note that with the installed extensions, you get the full support of AutoFill.

Also, note that you can still query IntelliSense and Autofill by placing the cursor at the desired location and pressing Ctrl-Space, which will show you which VS code recommendations are based on your current location. This seems familiar when using Eclipse; This is the same keyboard shortcut.

Enter the text "Get . " in the new MyController class, and you will get the code snippet for Autofill GetMapping; forward and select. This will create a basic GET mapping that we'll be modifying, as shown in List 2.

Create a Svelte frontal

Now we open a new terminal — you can manage the side of the terminal by the side by choosing Terminal -> Split Terminal. Then, in the new airport, go to the appropriate directory (not part of the Java project) and use the commands in list 3 to create a new Svelte interface.

Listing 3. Slender front scaffolding

npx degit sveltejs/template vs-java-frontend

Now YOU can go to localhost: 5000 and view the Svelte homepage.

Add the front-end to the workspace.

Then right-click the File Explorer under the demo project and select Add Folder to Workspace. Access to your newly created client project through Svelte. It adds an interface VS code as part of the project workshop so we can change it.

Now add the VS-Code extension to Svelte VS-Code in the same way as the Java extensions above. Once the extension is installed, VS Code can process both the previous final Java structure and a Java backup.

Connect the front and back ends

We can test the internal communication with the critical combination Ctrl-Shift-P to open the file app. svelte and change it like list 4 to change the script element.

Listing 4. Hitting the back-end

export let name;

async function loadData()<

let response = await fetch("http://localhost:8080");

name = await response.text();

List 4 performs a function that triggers a simple GET question for our endpoint and stores the answer in a named variable reflected in the tag.

Java runtime configuration

To obtain and configure the Java Runtime Environment information, you can open the Command Palette (Ctrl-Shift-P) and open Configure the Java Runtime Environment. You will see a screen like a Figure 2.

Figure 2. Java runtime configuration

Please note that VS Code identifies the JDK you have installed and determines which projects and which version to use. It also allows you to install a newer version of the IDE.

Debugging Java

Debugging Java in VS code is also easy. Stop the demo program while it is running. Right-click the DemoApplication file and select Debug. Spring Boot is running in debug mode.

To set a breakpoint, open MyController and double-click on the red point to the left of the 14 lines. Now localhost: reload 5000 pages. Finally, the breakpoint is occupied, and you will see the screen shown in Figure 3.

Figure 3. Debugging a Java File

Note that in the menu bar, you will continue, enter, skip, etc.

Running tests

Now open the DemoApplicationTests.java file created by Spring Initializer. Note that the running tests are open. Click here. (You can also right-click the file and select Start Java.) The tests are running, and a checkmark is displayed to see the test results, as shown in Figure 4.

Figure 4. Display of JUnit results

Saving the workspace configuration

When you close VS Code, you will be prompted to save the workspace configuration named workspace. Code-workspace. Save your settings and open the project again to find all of your settings.

VS Code for Java

The Java feature in the Visual Studio code is comparable to a standard Java IDE with exact extensions installed. The difference: VS code is lighter, more responsive and requires minimal effort.

This speed and simplicity, along with the ability to seamlessly use other collections of technology — you see the meaning that you don't have to change gears or fight setup time in the new environment — makes VS code a compelling opportunity for Java development. Like the popularity of WooCommerce request a quote plugin boosts the development process of WooCommerce plugins to support Woo store endlessly.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *