'VS Code environment variable similar to eclipse

In eclipse N number maven tasks with VM arguments and specific environment variables can be maintained

each can be individually launched with given names

How do we achieve this in VS code, is there any extension or json files like runner or run with launch with ?



Solution 1:[1]

You have to configure your own tasks in vscode in the file tasks.json. There is a very good documentation here.

As an example how to call a simple shell script:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run shell script",
      "type": "shell",
      "command": "./script.sh"
    }
  ]
}

If you want to set environment variables you have to use the options:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run shell script",
      "type": "shell",
      "command": "./script.sh",
      "options": {
        "env": {
            "PATH": anotherpath;${env:PATH}"
        }
      }
    }
  ]
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1