对于使用 Visual Studio Code 的 Java 开发者来说,Language Support for Java(TM) by Red Hat 扩展提供了非常好的语言特性支持,比如智能感知和项目支持等。然而,我们也听到一些用户反馈需要调试 Java 程序。今天,我们万分激动地宣布,我们与 Red Hat 合作开发了能让开发者调试 Java 应用程序的轻量级扩展:Java Debugger for Visual Studio Code,它基于 Java Debug Server

注意: Java Debugger for Visual Studio Code 和 Java Debug Server 都将在发布初始版后不久开放源码。

 

为了让 Java 开发者能尽快开始使用 VS Code,我们也创建了一个 Java 扩展包,它包含了 Language Support for Java(TM) by Red Hat 和 Java Debugger for Visual Studio Code 这两个扩展,这样你不需要单独去搜索安装这些扩展。这是刚刚开始创建的一个现代 Java 工作流程,将来我们会往 Java 扩展包中添加更多特性和扩展。

 

开始

从以下步骤开始:

  1. 在 Visual Studio Code 中打开扩展视图(Ctrl+Shift+X)。

  2. 输入“java”以过滤扩展列表。

  3. 找到并安装 Java Extension Pack (Java 扩展包),如果你已经安装了 Language Support for Java(TM) by Red Hat,也可以单独找到并安装 Java Debugger for Visual Studio Code 扩展。

你也可以直接从本文中安装 Java 扩展包:

安装 Java 扩展包    (安装了 VSCode 的情况下,点击上面的链接即可调用 VSCode 进行安装)

重启 VSCode,打开包含 Java 项目的代码,然后按下面的步骤进行:

  1. 准备项目。打开一个 .java 文件,Java 扩展会激活。Maven、Gradle 和 Eclipse 项目都能得到支持。这个扩展会自动构建项目,不需要手工触发构建。

  2. 开始调试。切换到调试视图(Ctrl+Shift+D),打开 launch.json 并添加 Java 调试配置。

  3. 在 mainClass 中填入要启动的类,或者在 hostName 中填入要附加的主机名以及在 port 中填入端口。

  4. 设置断点并按 F5 开始调试。

支持的特性

在这个版本中,我们支持以下特性:

  • 启动/附加 - 你可以在 VS Code 中启动一个 Java 项目,也可以附加到一个在本地或远程端以调试模式运行的 JVM 进程。

  • 断点 - 支持表达式条件或命中条件断点,可以在内置的断点设置容器中轻松进行设置。因此你可以直接在源代码视图中插入断点,不需要弹出容器,非常方便。按异常中断也得到了支持。

  • 控制流 - 包括 暂停、继续 F5、单步 F0、步进 F11、步出(跳出) Shift+F11。

  • 数据审查 - 当程序停止在断点上的时候,调试器可以访问当前内存中的变量名和值。支持查看/监视/设置变量值。

  • 诊断 - 调用栈 面板会显示程序的调用栈,你在这个面板中可以在捕获的调用路径中随意跳转。多线程调试也通过并行栈得到支持。

  • 调试控制台 - 可以从调试控制台看到标准输出和错误输出信息。

官方文档:
 

The Java support in VS Code is provided through extensions and optimized for lightweight Java projects with a simple, modern workflow. Popular extensions in the Marketplace provide project support, code completion, linting, debugging, code formatting, snippets, and more.

Download VS Code - If you haven't downloaded VS Code yet, quickly install for your platform (Windows, Mac, Linux).

Install Java Extensions

VS Code is a fast editor and ships with only the basic features. Add Java language support to VS Code by installing the popular Java extensions.

  1. In Visual Studio Code, go to the Extensions view (Ctrl+Shift+X).
  2. Filter the extensions list by typing "java".

To help set up Java on VS Code, there is a Java Extension Pack which contains two popular extensions:

  1. Language Support for Java(TM) by Red Hat
  2. Java Debugger for Visual Studio Code

Install the Java Extension Pack

This document describes the features included in the Java Extension Pack.

Java Project Support

Maven, Eclipse and Gradle Java project are supported through Language Support for Java(TM) by Red Hat, by utilizing M2Eclipse which provides Maven support and Buildship which provides Gradle support through the Eclipse JDT Language Server.

Please note that Gradle-based Android projects are not supported.

Editing and Navigating Code

Linting

linter is a tool that provides warnings for suspicious looking code. Language Support for Java(TM) by Red Hat provides this feature to report parsing and compilation errors as you type, so you can fix them inside VS Code.

Intellisense

VS Code also supports code completion and Intellisense for Java through Language Support for Java(TM) by Red HatIntellisense is a general term for a number of features, including intelligent code completion (in-context method and variable suggestions) across all your files and for built-in and thirty-party modules.

Search for symbols

You can search for symbols in the current file or workspace to navigate your code more quickly.

To search for a symbol in the current file, use Quick Open (Ctrl+P) then enter the '@' command, then enter the name of the symbol you're looking for. A list of potential matches will appear and be filtered as you type. Choose from the list of matches to navigate to its location.

To search for a symbol in the current workspace, start by pressing Ctrl+T, then enter the name of the symbol. A list of potential matches will appear as before. If you choose a match that was found in a file that's not already open, the file will be opened before navigating to the match's location. Alternatively, you can also use Quick Open (Ctrl+P) then enter the '#' command to search the current workspace.Ctrl+T is just the shortcut for the '#' commands, respectively, so everything works the same.

Peek Definition

You can take a quick look at how a symbol was defined by using the Peek Definition feature. This feature displays a few lines of code near the definition inside a peek window so you can take a look without navigating away from your current location.

To peek at a symbol's definition, place your cursor on the symbol anywhere it's used in your source code and then press Alt+F12. Alternatively, you can choose Peek Definition from the context menu (right-click, then choose Peek Definition).

Go to Definition

You can also quickly navigate to where a symbol is defined by using the Go to Definition feature.

To go to a symbol's definition, place your cursor on the symbol anywhere its used in your code and then press F12. Alternatively, you can choose Go to Definition from the context menu (right-click, then chooseGo to Definition). When there's only one definition of the symbol, you'll navigate directly to its location, otherwise the competing definitions are displayed in a peek window as described in the previous section and you have to choose the definition that you want to go to.

Other code editing features include:

  • Code formatting
  • Code snippets
  • Code outline
  • Code lens (references)
  • Javadoc hovers
  • Rename
  • Highlights

Debugging

Java Debugger for Visual Studio Code is a lightweight Java Debugger based on Java Debug Server. It works with Language Support for Java by Red Hat to allow users debugging Java code using Visual Studio Code (VS Code).

The Java Debugger supports following features:

  • Launch/Attach - You can either launch the Java project within VS Code or attach to any running JVM process in debug mode, locally or remotely.
  • Breakpoints - Conditional breakpoints by Hit Count is supported and can easily be set using the inline breakpoint settings window. This allows you to conveniently add conditional breakpoints to your code, directly in the source viewer, without requiring a modal window. Break on exceptions is also supported.
  • Control flow - Including Pause, Continue F5, Step over F10, Step into F11, Step out Shift+F11
  • Data inspection - When you're stopped at a breakpoint, the debugger has access to the variable names and values that are currently stored in memory. Inspect/Watch/Set Variables are supported.
  • Diagnostics - The CALL STACK panel shows the call stack of your program and allows you to navigate through the call path of each captured allocation. Multi-threaded debugging is supported by parallel stacks.
  • Debug Console - The Debug Console lets you see information from both stdout and stderr.

You can launch the debugger following steps below:

  1. Switch to the Debug view (Ctrl+Shift+D).
  2. Open launch.json to add a debug configuration for Java
  3. Fill in the mainClass for Launch setting or hostName and port for Attach.
  4. Click Start button or press F5 to start debugging.

Next Steps

Read on to find out about:

  • Basic Editing - Learn about the powerful VS Code editor.
  • Code Navigation - Move quickly through your source code.
  • Tasks - use tasks to build your project and more
  • Debugging - find out how to use the debugger with your project

JAVA 基础--开发环境 vscode 搭建的更多相关文章

  1. JAVA 基础开发环境 vscode 搭建 Windows下VSCode编译运行简单java

    JAVA 基础开发环境 vscode 搭建 来源 https://www.cnblogs.com/freewsf/p/7744728.html 对于使用 Visual Studio Code 的 Ja ...

  2. JAVA 基础--开发环境IDEA 搭建

    1.下载IDEA  (500M+) 2.激活. 在网站http://idea.lanyus.com/中获取注册码,填入Activation code中: 然后点击Activate即可. 3.创建工程前 ...

  3. Java Web 开发环境快速搭建

    Java Web 开发环境快速搭建 在因某种原因更换开发设备后,可依据此文快速搭建开发环境,恢复工作环境. Java开发环境: Windows 10 (64-bit) Oralce JDK Eclip ...

  4. 面试题-Java基础-开发环境

    1.什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行的字节码文件.Java被设 ...

  5. JAVA WEN开发环境与搭建

    一.下载安装JDK1.配置jdk开发环境JAVA_HOME 2.path 二.下载安装eclipse javaEE版本 三.安装部署tomcat3.1.安装: 直接解压到指定目录即可.(注:目录不要太 ...

  6. JAVA 基础--开发环境Sublime Text 3 搭建

    方法一  打开Sublime Text 3,依次点击Preference, Browse Packages,在打开的窗口中双击User文件夹,新建文件JavaC.sublime-build,用记事本打 ...

  7. JAVA WEB开发环境与搭建

    一:jdk下载与安装 (1)官网下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-506665 ...

  8. java基础开发环境安装(全)

    一.jdk安装(可以根据自己习惯选择合适安装路径) 1.jdk1.8下载地址:https://pan.baidu.com/s/1O9JQlFJ9cpkGCQL35cm_7g 提取码:pe2g 2.jd ...

  9. java+tomcat开发环境搭建

    java+tomcat开发环境搭建 一.jdk环境变量设置 ...........这里省略n个字............. 二.tomcat环境变量设置 安装好tomcat后 1.新建环境变量: CA ...

随机推荐

  1. MyBatis学习总结(一)

    MyBatis,是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用简单的XML或注解 ...

  2. IDEA在debug模式项目启动一半卡主,无法启动,也不报错

    罪魁祸首就是手误 点了一下代码中方法的左侧打了个方法断点 Java Method Breakpoints 有时候debug启动很慢也有可能是这个原因,记录一下

  3. JAVA基础之项目分包

    个人理解: 项目分层分包适合多人开发合作的,最好一个界面设置一个view,同时注释一定设置好,按照顺序:从前向后进行传递参数,从后向前进行传递返回值来进行判断是否真正的执行了sql语句(可以不返回), ...

  4. ES6学习(2)

    Set和Map数据结构 ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. const s = new ...

  5. nmap -sS

    SYN 扫描,半连接,受到syn/ack响应后意味着端口开放,收到rst包意味着端口关闭.

  6. <转>Java 高并发综合

    并发模型 悲观锁和乐观锁的理解及如何实现,有哪些实现方式? 悲观锁 悲观锁假设最坏的情况(如果你不锁门,那么捣蛋鬼就会闯入并搞得一团糟),并且只有在确保其他线程不会干扰(通过获取正确的锁)的情况下才能 ...

  7. Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  8. Codeforces Round #319 (Div. 2) C Vasya and Petya's Game (数论)

    因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k &&am ...

  9. IntelliJ IDEA Debug模式的启动

    在服务器启动参数中加入: -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 在程序中设置断点. 运行程序,将停留在断点处. = ...

  10. macbook secureCRT终端中文乱码的问题

    最近mac用crt中文总是显示的是一串串问号, 而用自带的终端软件就不会出现乱码, 经过一番折腾暂时解决了这一问题, 方法如下: 1. 打开终端操作 sudo vim /etc/profile 在最后 ...