本文介绍了VSCode Java调试器“错误无法打开'thing.java':找不到文件(\thing.java)。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在VSCode中调试java时收到此错误:
错误无法打开'thing.java':找不到文件(\thing.java)。

I am receiving this error when try to debug java in VSCode:Error Unable to open 'thing.java': File not found (\thing.java).

调试器似乎正在运行(我的代码暂停,我可以看到局部变量并逐步执行,但源代码未显示)。

The debugger seems to be running (my code is paused, I can see local variables and step through, but the source code is not being shown).

这是我的launch.json:

Here is my launch.json:

{
  "name": "Java",
  "type": "java",
  "request": "launch",
  "stopOnEntry": true,
  "preLaunchTask": "build",
  "jdkPath": "${env:JAVA_HOME}/bin",
  "cwd": "${workspaceRoot}",
  "startupClass": "my.package.classname",
  "options": [
    "-classpath",
    "${workspaceRoot}/bin"      
  ]
}

我做错了什么?如何显示源代码?

What am I doing wrong? How can I get the source code to show?

推荐答案

它出现(VSCode的Java调试器)无法找到源文件。这是一个,这似乎是固定的。

It appears javaVSCode (Java debugger for VSCode) is having trouble locating the source files. This was an issue for this, and it appears to be fixed.

不幸的是没有文件。因此,在查看合并和一些实验后,答案是:

Unfortunately there was no documentation. So, after looking through the merge and some experimentation, the answer is to:

在配置中添加sourcePath选项

例如。

{
  "name": "Java",
  "type": "java",
  "request": "launch",
  "stopOnEntry": true,
  "preLaunchTask": "build",
  "jdkPath": "${env:JAVA_HOME}/bin",
  "sourcePath": ["${workspaceRoot}/src/my/package"],
  "cwd": "${workspaceRoot}",
  "startupClass": "my.package.classname",
  "options": [
    "-classpath",
    "${workspaceRoot}/bin"      
  ]
}

这篇关于VSCode Java调试器“错误无法打开'thing.java':找不到文件(\thing.java)。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 14:41