5

I am a C#, c++ developer. If I have the code and pdbs to external dlls, I am able to step into the code of the external dll, by pointing IDE to the code and/or the PDBs. I want to do something similar with Java JARs

I have created a Micro Service framework in java using Visual Studio code. This compiles into a jar file. I have another application that is consuming this jar file. When I am debugging my application, how can I step into the code of the Micro Service jar?

I am using VS Code 1.45.1, zulu 14, maven 3.6.3

Say I have a jar file called MyMaths.jar, inside it there is a class mybasicmaths

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

This jar is being used by another application consuming the MyMaths.jar. I have resolved the dependencies using Maven. In the client application, I have code like

    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);
       }
    }

I am able to run my project fine. But I want to be able to stepinto the code of MyBasicMaths.addNums() from MyMathsConsumer.

When I am debugging, I am able to step into amqp-client-5.7.3.jar and even zulu classes, but not into the jar file I have created.

Similar question has been asked for eclipse Attach the Source in Eclipse of a jar

I am asking the same for Visual Studio Code.

Anand
  • 316
  • 1
  • 14
  • You need to put more details like your code, different ways you have tried but couldn't get the solution. This will help others to better answer your question. Do have a look @ https://stackoverflow.com/help/how-to-ask – Lazycoder-007 May 27 '20 at 11:11
  • @Lazycoder_007 hope the question is clearer? – Anand May 27 '20 at 12:37
  • were you ever able to figure this out? – Emmanuel F Nov 11 '20 at 20:50
  • @EmmanuelF I switched to using IntelliJ. IntelliJ is able to stepinto my jars. But if you can attach you source, you may be able to step in, please check the link https://maven.apache.org/plugin-developers/cookbook/attach-source-javadoc-artifacts.html – Anand Jan 28 '21 at 07:24

1 Answers1

4

(from 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"
    }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Andrew
  • 2,943
  • 18
  • 23