0

I have this command to get output from a program:

project_path/data $ java -classpath ../jars/jdom.jar:[etc, more jars] path/to/class/MainClass config.xml command arg1 arg2

When I do this, I get the output I expect. But I want to be able to debug it so I can step through as the code runs.

So I tried making a launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "request": "launch",
            "name": "Run Project",
            "cwd": "${workspaceRoot}/data",
            "mainClass": "path.to.class.MainClass",
            "args": ["config.xml", "command", "arg1", "arg2"]
        },
    ]
}

However, when I do it this way I always get an error that the config file cannot be found, so it seems like something about the paths is not being resolved the same way when I run a JVM directly from the terminal as when I try to call the class directly with a launch.json, but because I'm not super familiar with Java I don't know how to fix this.

Liz C.
  • 101
  • 8

1 Answers1

0

A JAR ("Java archive") file is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. JAR files are archive files that include a Java-specific manifest file. They are built on the ZIP format and typically have a .jar file extension.

You can debug a jar file, but without seeing the actual source code that you want to understand, you won't get too much benefit. This is how.

how can I debug a jar at runtime?

In order to debug a Java application, line by line, you will need the source code. Since you have the jar file, you can get the source code using this tool.

http://java-decompiler.github.io/

Then download Visual Studio Code IDE (it's free). Looks like you already have it! Install the Java extension. Then you should be able to compile your .java files into .class files and step through your code since the IDE has tools to do so.

To do both, use this reference:

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

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245