第一步,尝试从命令行编译程序。例如。如何在 Windows 上从命令行运行 Java 程序? https://stackoverflow.com/questions/16137713/how-do-i-run-a-java-program-from-the-command-line-on-windows是一个好的开始。您可以直接在 VSCode 的集成终端中运行命令。
(可选)从该命令创建 VS Code 构建任务,以使用该构建命令运行构建。
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Foo",
"type": "shell",
"command": "javac foo.java",
"problemMatcher": []
}
]
}
要运行/调试,请在调试视图中创建启动配置,例如:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-Foo",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "Foo",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}