0

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?

2 Answers 2

2

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"      
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

sourcePath has now chagned to sourcePaths
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.