diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala index 9e59e89376e..7ebf445ee15 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala @@ -427,9 +427,16 @@ class DebugProvider( if params.getDataKind == b.DebugSessionParamsDataKind.SCALA_MAIN_CLASS => json.as[b.ScalaMainClass] match { case Success(main) if params.getTargets().size > 0 => + val javaBinary = buildTargets + .scalaTarget(params.getTargets().get(0)) + .flatMap { + _.jvmHome.map(path => path.toAbsolutePath.resolve("bin/java")) + } + .filter(_.exists) + .orElse(userConfig().usedJavaBinary) val updatedData = buildTargetClasses.jvmRunEnvironment .get(params.getTargets().get(0)) - .zip(userConfig().usedJavaBinary) match { + .zip(javaBinary) match { case None => main.toJson case Some((env, javaHome)) =>