VSCode Java Debugger “Error Unable to open 'thing.java': File not found (\thing.java).”

风格不统一 提交于 2020-01-11 14:04:22

问题


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?


回答1:


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"      
  ]
}



回答2:


This problem happen if you don't have JAVA_HOME set to your environment:

Run in terminal: echo $JAVA_HOME

If nothing appears, just set it: export JAVA_HOME=/usr/java/your-jdk-version/



来源:https://stackoverflow.com/questions/44022422/vscode-java-debugger-error-unable-to-open-thing-java-file-not-found-thing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!