PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 22, 2022

[FIXED] How to set JAVA environment variable in VS Code

 August 22, 2022     environment-variables, gradle, java, visual-studio-code     No comments   

Issue

I have a spring-boot project and my IDE is VS code. I want to pass an environment variable to my applications. Right now I set it before the Gradle command

export PROJECT_NAME=test

./gradlew bootrun

PROJECT_NAME is my env variable and I access this in application.properties

what is the recommended approach to set environment variables in VS code for java


Solution

In order to set environment variable for Spring boot application in VSCode, the recommended way is to create a launch.json file in .vscode folder of your project, then add the "env" section like the example below:

{
  "configurations": [
    {
      "type": "java",
      "name": "Spring Boot-DemoApplication<demo>",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "console": "internalConsole",
      "mainClass": "com.example.demo.DemoApplication",
      "projectName": "demo",
      "args": "",
      "env": {
        "PROJECT_NAME": "FOO_PROJECT"
      }
    }
  ]
}


Answered By - MinhTC
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing