头图
Recently, Microsoft's development tool VSCode has frequently updated Java support, and it supports SpringBoot and Lombok. I can't help but wonder if VSCode is also competent for Java development? So I took the time to experience it, and it is indeed completely competent. Java developers have a new choice, which is not only easy to use but also open source! Today, I will take you to experience VSCode, the experience surpasses Eclipse, and does not lose IDEA!

SpringBoot actual e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall

Introduction to VSCode

VSCode stands for Visual Studio Code. It is an integrated development tool open sourced by Microsoft. It is currently available on Github 135K+Star . VSCode claims to be able to redefine the code editor. It is not only free but also open source and can be used on multiple platforms. Compared with IDEA, VSCode is not only more lightweight, but also faster to build and respond!

Let's take a look at the renderings of using VSCode to develop Java projects. The interface is quite cool!

Download and install

Next we will download and install VSCode to give it the ability to develop Java applications.
  • First of all, we need to download the installation package of VSCode. Downloading the compressed version is simple and fast. The download address is: https://code.visualstudio.com/Download

  • After the download is complete, extract it to the specified directory, double-click the .exe file to start it;

  • If the system we start is a Chinese environment, VSCode will prompt you to download the Chinese plug-in, and download it decisively;

  • The next step is to install various plug-ins to facilitate our development. First, install the Java family bucket plug-in provided by Microsoft Extension Pack for Java . This plug-in contains 6 basic Java extension plug-ins, which can meet our basic needs for developing Java programs. ;

  • This Java family bucket plug-in currently has 1390w downloads. It seems that many Java developers have already started to use VSCode;

  • Since we usually use SpringBoot for development, we also need to install the SpringBoot family bucket plug-in, which contains 3 SpringBoot extension plug-ins;

  • I wanted to install the Lombok plug-in again. Later, I found that VSCode has built-in Lombok support, which can be turned on in the settings. After installing these plug-ins, you can start developing Java programs.

use

Next, I will take my open source e-commerce project mall as an example to talk about how to use VSCode to develop SpringBoot applications.

Configure font size

Before using the code editor, many friends will have the habit of configuring the font size. The way to configure the font size in VSCode is very simple. Click directly in the 外观 settings 放大 or 缩小 button.

Import Maven project

  • Since VSCode is only a development tool, it will not directly integrate Maven like IDEA. Here we need to install Maven and configure environment variables. First download the Maven installation package, download address: https://maven.apache.org/download. cgi

  • After the download is complete, extract it to the specified directory, and then configure the system environment variables;
 MAVEN_HOME=D:\developer\env\apache-maven-3.8.6
Path+=%MAVEN_HOME%\bin

  • Unzip it to the specified directory, and then open the directory through the 打开文件夹 button, and then the project will be automatically built. Personally, the construction speed is much faster than IDEA;

  • Let's take a look at the code editing interface, which is still very cool!

Run the debug project

  • The way to run and debug the code is very simple, just click the run button in the upper right corner;

  • Since my mall project uses SpringBoot, I can also use Spring Boot Dashboard to run, is it similar to running the project in IDEA;

  • We can also debug by breaking points. The variable area on the left will display the values of all local variables. You can skip and jump out of breakpoints through the top button. When the mouse hovers over the variable, the value of the variable will be displayed. IDEA Some of the functions in VSCode are basically there!

Browse project code

  • When we usually look at code, we often need to search by class name, which can be achieved by using Ctrl+T shortcut key in VSCode;

  • If you want to search directly by the file name, you can use the shortcut key Ctrl+P ;

  • Use Ctrl+鼠标左键 to jump directly to view the source code of the class;

  • Sometimes when we view the source code of a third-party library, there will be no comments, but in IDEA, we click the class name to automatically download the source code. At this time, we only need to download the source code through the following command in the root directory of the project;
 mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true
  • Maven only downloads xxx.jar Jar package by default, such as xxx-sources.jar This annotated source package needs to be downloaded by itself;

  • Since Microsoft's IntelliCode plugin is installed by default, VSCode's code prompts are still very smart;

  • We can also quickly find the variables and methods in the class through the outline view on the left. Most of the common functions in IDEA are basically supported by VSCode. Interested partners can experience it by themselves.

hot key

The functions of VSCode are still very powerful, and it is completely sufficient for Java application development. Here I have compiled a set of common shortcut keys for VSCode based on the shortcut keys that I usually use in IDEA. You can try them.
  • View class source code: Ctrl+鼠标左键
  • Shortcut command search: Ctrl+Shift+P+命令名称
  • Search files by filename: Ctrl+P
  • Find classes by class name: Ctrl+T
  • Comment code: Ctrl+/
  • Turn on/off the sidebar: Ctrl+B
  • Global Find and Replace: Ctrl+Shift+F
  • Find in file: Ctrl+F
  • Modify variable or class name: Fn
  • Find references to variables or classes: Shift+F12
  • Find the implementation of an interface or method: Ctrl+F12
  • Formatting code: Shift+Alt+F
  • Refactoring to extract variables or methods: Ctrl+Shift+R
  • Rollback to previous operation: Alt+左箭头
  • Advance to next action: Alt+右箭头
  • Prompt for possible operations, such as variable generation: Alt+.
  • Move one line of code: Alt+上箭头 or Alt+下箭头
  • Delete the current line of code: Ctrl+Shift+K

Summarize

Today I tried to use VSCode to develop SpringBoot applications, and it is really competent! VSCode not only has a cool interface and powerful functions, but also has a lot of plugins in the plugin market. Compared to IDEA, it is faster to build and more responsive. Although there are some small details that are not as good as IDEA, for example, the console cannot output colored logs, and the source code of annotated third-party libraries needs to be downloaded manually. However, the VSCode function update is very fast, and I believe it will soon become a better Java development tool!

References

Official documentation: https://code.visualstudio.com/docs/languages/java

Project source code address

https://github.com/macrozheng/mall


macrozheng
1.1k 声望1.3k 粉丝