Issue setting project-level environment variables using WSL2, Ubuntu, Windows 11, VSCode and Hilla

I have been playing around with all different ways to set environment variables in my setup and am struggling to get any to show when running System.getenv() apart from when I explicitly execute export VARIABLENAME=secretValue in the terminal right before running the project.

I’ve tried;

  • VSCode’s launch.json,
  • creating an .env file,
  • setting envrionment variables in windows,
  • using the Maven VSCode extension settings config variables,
  • editing .profile,
  • editing .bash_profile

But I just can’t seem to get something that isn’t the inline entry being picked up in my Hilla runtime after executing ./mvnw

How can I set environment variables that actually work where I can set them at a project level and without resetting them in my terminal manually every time? Assumedly I shouldn’t be editing the ./mvnw script as that would be committed to git…

Please help! New to Java and Maven too so might need to ELI5 if I’m missing something obvious. Copilot picked up my stack overflow question content and repeated it back to me when I asked :smiley:


Not sure if this is what you looking for, but a Hilla project is a standard Spring Boot project. Project level configuration properties can be set in numerous ways in Spring Boot. You can declare them in src/main/resources/, for example. You can have multiple of those property file, each representing another environment, like development or production. They are called profiles in Spring Boot.

1 Like

You can set any env variable in


where ‘PORT’ is an environment variable, ‘8081’ - default value