In this post under DotEnv I will show with example what is the purpose of “ignoreIfMissing” method with an example. In my previous posts I showed with example how to load environment files whether it is “.env” file or custom env file like “custom-file.env”. The default behavior of DotEnv framework is that if the environment…… Continue reading ignoreIfMissing method example
Category: DotEnv
Loading environment properties from custom .env file
In all my previous post under DotEnv, I showed how to load environment properties from a file named “.env”. The “.env” file can be present in the project directory or in some other directory. By default, DotEnv is configured to search under project directory. In one of my previous posts, I showed how to change…… Continue reading Loading environment properties from custom .env file
Loading .env file from a specific folder
In previous post under DotEnv, I showed that by default DotEnv checks for “.env” file in the project directory when static “load” method is called. So if your project directory is in “D:\ProgrammingConcepts\JavaSEConcepts\DotEnvConcepts” the “.env” file should be present directly under the “DotEnvConcepts” folder. If present in subfolders under “DotEnvConcepts” it will not load that…… Continue reading Loading .env file from a specific folder
Accessing an environment variable
In this post under DotEnv, I will show with example how to access a particular environment variable. For example I have created “.env” file with below data. Env File MY_ENV_VAR1=some_value1 MY_ENV_VAR2=some_value2 Now to retrieve the value of environment variable “MY_ENV_VAR1” we call the non static “get” method of “DotEnv” class as shown below Main class…… Continue reading Accessing an environment variable
Loading .env files
In this post under DotEnv, I will show with example how to load a .env file. Below is the complete main class Main class 1 package defaultPackage; 2 3 import io.github.cdimascio.dotenv.Dotenv; 4 import io.github.cdimascio.dotenv.DotenvEntry; 5 6 public class Example1 { 7 public static void main(String[] args) { 8 Dotenv dotenv = Dotenv.load(); 9 for(DotenvEntry entry…… Continue reading Loading .env files