作为一个喜欢折腾的人,最近抽空折腾一下VScode怎么写java程序。不断更新中。。

附一个原来写的C++的:这两个链接,第二个稍微简单一些

1)Visual Studio Code配置C、C++环境/编写运行C、C++(Windows)

2)Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(Windows)【真正的小白版】

此文对于已经配置好java开发环境的读者,如何配置java开发环境见下面几篇文章:(随便一篇就可以啦)

JAVA开发环境的搭建(配置JAVA开发环境)

Java 开发环境配置

JAVA开发环境的搭建(配置JAVA开发环境)以及使用eclipse从头一步步创建java项目

当已经配置好了java后,可以进行下面的操作了:

更新:因为文章是很长实践之前写的,简单来说,安装这个拓展:Java Extension Pack,里面包含这些东西很全

建议直接看英文官方文档(我粘贴在下面了),写的很全,官方逼死同人系列

------------------------------------------------------------------------------------------------------------------------------

这里先放一篇文章(这篇文章有些旧了似乎)和一篇官方文档

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

为了让 Java 开发者能尽快开始使用VS Code,我们也创建了一个Java 扩展包,它包含了Language Support for Java™ 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™ 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。

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

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

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

---------------------------------------------------------------------------------------------------------------------

官方文档:

Java in Visual Studio Code

The Java support in Visual Studio Code is provided through extensions and optimized for lightweight Java projects with a simple, modern workflow. Popular extensions in the Marketplace provide essential language features such as project support, code completion, linting, debugging, testing, code formatting, snippets, as well as tooling integration including Maven and Tomcat.

Install Java Extensions

VS Code is a fast editor and ships with great editing features. Add Java language support to VS Code by installing the popular Java extensions. To help set up Java on VS Code, there is a Java Extension Pack which contains popular extensions we picked for most Java developers:

  1. Language Support for Java™ by Red Hat
  2. Debugger for Java
  3. Java Test Runner
  4. Maven for Java

Install the Java Extension Pack

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

  1. Spring Boot Support
  2. Spring Initializr Java Support
  3. Tomcat
  4. CheckStyle

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 (Ctrl+Shift+X).
  2. Filter the extensions list by typing “java”.

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

Java Project Support

Maven, Eclipse and Gradle Java project 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 Archetype, browse through all the Maven projects within your workspace, and execute Maven goals easily from an embedded explorer.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-klIvx5lW-1653058572813)(https://code.visualstudio.com/assets/docs/languages/java/maven-explorer.png)]

Editing and Navigating Code

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C4fxbZmv-1653058572814)(https://code.visualstudio.com/assets/docs/languages/java/vscode-java.0.0.1.gif)]

Linting

A linter is a tool that provides warnings for suspicious looking code. Language Support for Java™ 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™ by Red Hat. IntelliSense 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 third-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 it is used in your source code and then press F12. Alternatively, you can choose Go to Definition from the context menu (right-click, then choose Go 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
  • CodeLens (references)
  • Javadoc hovers
  • Rename
  • Highlights

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 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 and expression evaluation are 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.
  • Hot Code Replacement - A very useful feature to facilitate experimental development and iterative trial-and-error coding.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-023Bnlm4-1653058572816)(https://code.visualstudio.com/assets/docs/languages/java/debug-features.png)]

The debugger is able to detect your launch class in most cases, all you need to do is start debugging by pressing F5. If you’d like to define the debugging configuration yourself, just follow the 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.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Edcje9Kk-1653058572817)(https://code.visualstudio.com/assets/docs/languages/java/java-debug.gif)]

For more debugging related information, please visit Java Debugging.

Testing

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gH3aIBGI-1653058572818)(https://code.visualstudio.com/assets/docs/languages/java/java-test-explorer.png)]

Your test cases are identified automatically.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GHEpGgvb-1653058572819)(https://code.visualstudio.com/assets/docs/languages/java/java-test.gif)]

Currently the Test Runner supports JUnit4. We’re working on JUnit5 and TestNG and will be supporting them soon.

Spring Boot and Tomcat

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

The Tomcat extension includes an explorer to easily navigate and manage your Tomcat servers. You can create, start, debug, stop and rename your Tomcat server all with the extension.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z8HmDteb-1653058572821)(https://code.visualstudio.com/assets/docs/languages/java/tomcat.gif)]

See Java Tutorial with VS Code to learn more about Tomcat and basic Java support with VS Code.

Spring Boot support is provided by an extension from Pivotal, who also provide extensions for popular platforms such as Cloudfoundry, Concourse and BOSH. There’s also a Spring Initializr Java Support extension so you can create a Spring Boot app from scratch.

See Spring Boot with VS Code to learn more about Spring Boot support with VS Code.

.

整理:使用 Visual Studio Code (vscode) 编写、运行、 调试 Java 应用程序相关推荐

  1. Visual Studio Code 如何编写运行 C、C++ 程序?

    本文面向初学者,但是不适合还在学写Hello World级别的初学者.阅读本文能在一定程度上了解程序编译的知识,以及使用VS Code的知识. 本文大部分内容都可从VS Code官方文档:C++ pr ...

  2. Visual Studio Code 如何编写运行 C、C++ 程序

    转载自https://www.zhihu.com/question/30315894/answer/154979413 侵删 作者:谭九鼎 链接:https://www.zhihu.com/quest ...

  3. 【环境配置】Visual Studio Code 如何编写运行 C、C++ 程序?

    作者:谭九鼎 链接:https://www.zhihu.com/question/30315894/answer/154979413 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...

  4. vs code怎么编译C语言,Visual Studio Code 如何编写运行 C、C++ 程序?

    要想进行debug,launch.json文件并不是必须的,只要有 tasks.json 文件即可. 最新操作: 0.安装MinGW,将其bin目录加入到系统变量的PATH中;在vs code中安装C ...

  5. Visual Studio Code如何编写运行C、C++

    Visual Studio Code如何编写运行C.C++ 作者:知乎用户 链接:https://www.zhihu.com/question/30315894/answer/154979413 来源 ...

  6. Visual Studio Code(VSCode) 编辑/编译/调试 C++ 代码

    前言 最近想要切换编辑工具,之前工作中使用过 Source Insight,Eclipse,CLion 来写 C++ 代码.目前来说 Source Insight 已经非常古老,只有编写代码还说得过去 ...

  7. qstudio c语言中文网,再整理:Visual Studio Code(vscode)下的通用C语言环境搭建

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 主要流程: 1.vscode的下载与简单配置 2.MinGw的下载与安装 3.配置系统环境变量 4 ...

  8. 整理:Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(主要Windows、简要Linux)

    2020年2月22日更新,又按照自己的帖子尝试了以下,感觉大的思路是没问题的啊,小改动用紫色的标记标注出来了,另外如评论区所说删去了部分旧版本的内容和图片,不知道为啥评论区的留言我都没收到邮件... ...

  9. vscode新建html运行js,用Visual Studio Code创建JavaScript运行环境

    什么是VSCode Visual Studio Code (简称 VS Code / VSC) 是一款于2015年由微软免费开源的现代化轻量级代码编辑器,支持几乎所有主流的开发语言的语法高亮.智能代码 ...

最新文章

  1. 全民自动驾驶5年内真的会来吗?这是Lyft的自动驾驶2.0
  2. sdi转hdmi转换器应用领域及规格参数详解
  3. qt将生成的程序打包在他人电脑上可用
  4. 有趣的编程代码_iPad amp; Mac 编程游戏推荐
  5. 计算机视觉应用开发功能图,《计算机视觉算法:基于OpenCV的计算机应用开发》 —1.3 理解计算机图像...
  6. github上完成个人的站点搭建
  7. 8、Python车牌数据集自动生成及其图片叠加
  8. Java 恋爱纪念日(日期问题)
  9. 安卓APP源码和设计报告——基于Android的垃圾分类系统
  10. 老主板怎么接机箱前面的USB和mic
  11. 修改 IDEA 中 @author 默认值
  12. 美国大学计算机科学专业排名2019,2019年美国大学计算机专业排名
  13. Nordic Thingy:52 SDK 安装及编译
  14. JavaScript11:事件
  15. (附源码)springboot学生宿舍管理系统 毕业设计 161542
  16. 人为什么活着系列之十六:具体的人具体的环境具体分析
  17. Cron Expressions——Cron 表达式
  18. html5图钉效果,新版图钉软件全方位升级
  19. C#接口与继承的区别
  20. Camera hal 之 CameraProvider

热门文章

  1. css选择器 自定义属性_使用CSS选择器和自定义属性升级项目
  2. 汇编语言学习-Dos下的调试工具debug的使用教程
  3. 关于开发app内部阅读pdf文件
  4. 2021-04-29 Ubuntu重启 关机命令
  5. 免费的产品项目研究辅助工具_产品经理很好的助手工具软件
  6. 【总结】PHP常见面试题汇总(四)。。。
  7. linux终端如何打开多个,如何同时显示多个终端
  8. 盐湖卤水中分离硼的工艺有哪些
  9. PyQt5打开文件目录(QTreeView)并在QT界面输出文件目录并双击文件返回文件目录名
  10. FileMaker Pro 2017使用JavaScript加载百度地图并与数据库记录同步切换