I have a mish-mash of different weird things that I’m trying to do, with a lack of experience in Java in general making it harder work that it needs to be.
I’m using all of VSCode (launched through WSL2), Windows 11, WSL2 (Ubuntu), Java 17, Maven, Hilla Framework, Spring Boot.
I’m launching the project through the WSL2 Terminal in vscode, and trying to set environment configurations/variables via the run
> open configurations
> launch.json
.
Following guidance online, I am then setting the following config:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Application",
"request": "launch",
"mainClass": "com.example.application.Application",
"env": { "DD_SITE": "SECRET", "DD_API_KEY": "SECRET_1", "DD_APP_KEY": "SECRET_2" }
},
{
"type": "java",
"request": "attach",
"name": "Attach to Application started using Maven",
"hostName": "localhost",
"port": 5247
}
]
}
But when accessing System.getenv("DD_API_KEY")
in my application – there are no environment variables present.
I also tried on the Maven for Java VSCode extension settings menu to set the Maven custom environment variables:
{
"workbench.colorTheme": "Default Dark+",
"typescript.updateImportsOnFileMove.enabled": "always",
"security.allowedUNCHosts": [
"wsl.localhost"
],
"maven.terminal.customEnv": [
{
"environmentVariable": "DD_SITE",
"value": "SECRET"
},
{
"environmentVariable": "DD_API_KEY",
"value": "SECRET"
},
{
"environmentVariable": "DD_APP_KEY",
"value": "SECRET"
}
]
}
With no luck.
What am I doing wrong? How do I get the Hilla Framework project to pick up my env variables from VSCode/a file local to the project? TIA!