Shabirmean
Shabirmean

Reputation: 2571

How to set java vmargs in vscode at workspace level

Is there a way I can set java VM arguments at workspace level? That is, not having to have it in each launch configuration in the launch.json. A specific argument I want to be used whenever a launch is triggered for the current workspace in vscode. I also don't want it to be global to all Java projects opened in vscode, just the current workspace.

I tried adding this in .vscode/settings.json, but it doesn't seem to use it.

{
  "java.jdt.ls.vmargs": "-javaagent:/Users/me/my-agent.jar"
}

Any suggestions? Ways to achieve this?

Upvotes: 7

Views: 19591

Answers (2)

SangLe
SangLe

Reputation: 139

You should add vmArms at workspace level in setting.json file of VSCode

Open user setting: ctrl + shift + p

from popup then you can search "Open User Setting (JSON)"

Add this line below into your user setting json file

"java.debug.settings.vmArgs": "-Dappname=LocalTest ..."

press F5 (default) to run single java file or you can right click at the current file and choose "Run java"

Upvotes: 4

user51
user51

Reputation: 10163

You should use vmArgs option in the .vscode/launch.json file, create an entry for java launcher configuration as below -

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

            {
                "type": "java",
                "name": "Debug (Launch) with Arguments Prompt",
                "request": "launch",
                "mainClass": "com.myapp.Main",
                "args": "${command:SpecifyProgramArgs}",
                "vmArgs" : "${command:SpecifyVMArgs}"
            }
        ]
        }

You can get the list of other options here https://code.visualstudio.com/docs/java/java-debugging#_launch.

Upvotes: 6

Related Questions