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).
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?
解决方案
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:
Add the "sourcePath" option to your configuration
eg.
{
"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"
]
}