代码亚军扩展只会让你在 “运行” 的Java文件。
要真正调试的Java“的文件按照快速一次性设置:
- 在VS代码安装Java Debugger Extension并重新加载。
- 在VS代码中打开一个空文件夹/项目。
- 创建你的java文件。
- 在同一文件夹中创建一个文件夹
.vscode
。
- 创建2个文件
.vscode
文件夹中:tasks.json
和launch.json
- 复制粘贴下面的配置在
tasks.json
:下面的配置
{
"version": "2.0.0",
"type": "shell",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"isBackground": true,
"tasks": [
{
"taskName": "build",
"args": ["-g", "${file}"],
"command": "javac"
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Java",
"type": "java",
"request": "launch",
"externalConsole": true, //user input dosen't work if set it to false :(
"stopOnEntry": true,
"preLaunchTask": "build", // Runs the task created above before running this configuration
"jdkPath": "${env:JAVA_HOME}/bin", // You need to set JAVA_HOME enviroment variable
"cwd": "${workspaceRoot}",
"startupClass": "${workspaceRoot}${file}",
"sourcePath": ["${workspaceRoot}"], // Indicates where your source (.java) files are
"classpath": ["${workspaceRoot}"], // Indicates the location of your .class files
"options": [], // Additional options to pass to the java executable
"args": [] // Command line arguments to pass to the startup class
}
],
"compounds": []
}
你是 全部设置为调试java文件,打开任何java文件并按F5(Debug-> Start Debugging)。
提示: *隐藏。在VS代码侧面探险类文件的代码VS开放settings
并粘贴以下配置:
"files.exclude": {
"*.class": true
}
这似乎只适用于单个代码文件,不会导入类路径中的任何内容。 –