Make dotenv env variables available in System.getProperty() too
See original GitHub issueQ: Why should I use dotenv.get(“MY_ENV_VAR”) instead of System.getenv(“MY_ENV_VAR”) A: Since Java does not provide a way to set environment variables on a currently running process, vars listed in .env cannot be set and thus cannot be retrieved using System.getenv(…).
Given that System.getenv("MY_ENV_VAR")
doesn’t allow adding new environment variables at runtime, the other option is to plug the dotenv configured variables into System.setProperty()
.
This will allow libraries to use either System.getProperty("MY_ENV_VAR")
or dotenv.get("MY_ENV_VAR")
.
A simple change would look like this after Dotenv is created.
Dotenv
.load()
.entries()
.filter(entry -> System.getProperty(entry.getKey) == null)
.forEach(entry -> System.setProperty(entry.getKey(), entry.getValue()));
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Java System.getProperty vs System.getenv - Baeldung
In this tutorial, we'll explore the differences between two System methods for reading system properties and environment variables.
Read more >Using env variable in Spring Boot's application.properties
Using Spring context 5.0 I have successfully achieved loading correct property file based on system environment via the following annotation
Read more >Using dotenv package to create environment variables - Medium
One solution for this is to use environment variables. These are local variables that are made available to an application.
Read more >24. Externalized Configuration - Spring
Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. You can use...
Read more >How to Easily Set-up Node Config (Best Practices)
DO THE DOTENV ... Dotenv is a great Node library that enables the use of a .env file that can hold environment variables...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I published a new blog with this update: https://blog.jongallant.com/2020/05/java-dotenv-azure-sdk-update/
Very cool. Thanks for doing this.