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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.