如何通过进入我在 Visual Studio 代码中有源代码的 jar 文件代码来调试代码?

How to debug code by stepping into jar file code for which I have the source code in Visual Studio Code?

我是一名 C#、C++ 开发人员。如果我有外部 dll 的代码和 pdb,我可以通过将 IDE 指向 PDB 的代码 and/or 来进入外部 dll 的代码。我想用 Java JARs

做一些类似的事情

我使用 Visual Studio 代码在 java 中创建了一个微服务框架。这会编译成一个 jar 文件。 我有另一个正在使用此 jar 文件的应用程序。调试应用程序时,如何单步进入微服务jar的代码?

我正在使用 VS Code 1.45.1、zulu 14、maven 3.6.3

假设我有一个名为 MyMaths.jar 的 jar 文件,里面有一个 class mybasicmaths

    public class MyBasicMaths{
       public int addNums(int a, int b) {
           return a+b;
       }
    }

此 jar 正被另一个使用 MyMaths.jar 的应用程序使用。我已经使用 Maven 解决了依赖关系。在客户端应用程序中,我有类似

的代码
    public class MyMathsConsumer {
       public static void main(String[] args) {
         int a = 10;
         int b = 20
         MyBasicMaths myObj = new myBasicMaths();
         int c = myObj.addNums(10, 20);
         System.out.println(c);
       }
    }

我可以 运行 我的项目很好。但我希望能够从 MyMathsConsumer 进入 MyBasicMaths.addNums() 的代码。

当我调试时,我可以进入 amqp-client-5.7.3.jar 甚至 zulu classes,但不能进入我创建的 jar 文件。

类似的问题已经被问到eclipse Attach the Source in Eclipse of a jar

我对 Visual Studio 代码也有同样的要求。

(来自 https://code.visualstudio.com/docs/java/java-project

By default, a referenced {binary}.jar will try to search {binary}-sources.jar under the same directory, and attach it as source if one match is found.

If you want to manually specify a JAR file as a source attachment, you can provide a key-value map in the sources field:

"java.project.referencedLibraries": {
    "include": [
        "library/**/*.jar",
        "/home/username/lib/foo.jar"
    ],
    "exclude": [
        "library/sources/**"
    ],
    "sources": {
        "library/bar.jar": "library/sources/bar-src.jar"
    }
}