Scorb
Scorb

Reputation: 1950

How do I provide launch option args to VSCode Java Debugger

I am reading though the readme on the VSCode Java Debugger github page.

On the page is specifies a list "Options" that can be provided. I do not know how I am supposed to provide these options. All I know is I installed the extension, and now when I press F5 the debugger starts.

Further up in the readme, it briefly mentions a launch.json file. This file does not exist for me.

How can I provide args options. Specifically I want to enable assertions.

Upvotes: 6

Views: 17077

Answers (2)

giulianopz
giulianopz

Reputation: 350

VSCode will create a launch.json file in the .vscode/ dir at the root of your project when you click on the "Run and Debug" icon on left panel:

enter image description here

Open the launch.json file. It can contain a list of configurations to launch your app. To enable assertions, add "vmArgs" ("args" are for arguments to be passed to main class) to the already present config stub:

{
        "version": "0.2.0",
        "configurations": [

            {
                "type": "java",
                "name": "Debug (Launch) with Assertions Enabled",
                "request": "launch",
                "mainClass": "com.myapp.Main",
                "vmArgs" : "-ea" //it accepts a string or an array of strings
            }
        ]
}

Upvotes: 7

Steven-MSFT
Steven-MSFT

Reputation: 8431

The launch.json file was the configuration of debugging, you can find it under '.vscode' folder. If you have not it, you can open Deubg panel(Ctrl+Shift+D) and click 'create a launch.json file' to create a launch.json file.

The launch.json file can contain a multi debug configurations located in "configurations" property and was separated by '{},'. In the Debug panel(Ctrl+Shift+D) you can choose different configurations to apply to debug.

Then you can easily understand how to apply the Options you mentioned to configure the launch.json file.

Such as this is the default configuration of java debug:

        {
            "type": "java",
            "name": "Debug (Launch) - Current File",
            "request": "launch",
            "mainClass": "${file}"
        },

Some configurations belong to VSCode, some were provided by the extension which you have activated.

In this example, 'type', 'name', 'request' was provided by the VSCode, you can refer to this page to know the means of them and to find out more VSCode related configurations.

And what you have mentioned configuration in readme, was provided by the 'Java' extension, they are extension related. Such as 'mainClass' in this example.

You can refer to Java-Run and Debug and Debugging of VSCode page for the details of What I am talking about.

Upvotes: 2

Related Questions