Lindsay-Needs-Sleep
Lindsay-Needs-Sleep

Reputation: 1451

VSCode Java Debugger "Error Unable to open 'thing.java': File not found (\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).

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?

Upvotes: 0

Views: 3999

Answers (2)

Lindsay-Needs-Sleep
Lindsay-Needs-Sleep

Reputation: 1451

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 "sourcePaths" option to your configuration

eg.

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

Upvotes: 2

Rodrigo Celebrone
Rodrigo Celebrone

Reputation: 346

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/

Upvotes: 0

Related Questions