Skip to content

Harium/dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenv

CircleCI Maven Central

An utility tool to handle .env files in Java.

Maven

<dependency>
  <groupId>com.harium</groupId>
  <artifactId>dotenv</artifactId>
  <version>1.0.7</version>
</dependency>

Example

Create a .env file and place it at the root folder of your project.

Get your variables using:

String myValue = Env.get("MY_SECRET");

Alternatively, you can use a custom path using the path parameter:

String myValue = Env.path("/home/user/myFolder").get("MY_SECRET");

Fallback

If your variable is not declared in .env, dotenv will try to load it from the environment variables.

How it works

Dotenv looks for a .env file and loads it's contents. When you call Env.get("MY_SECRET"); for the first time, dotenv will try to load all the variables and cache them.

At this repo you can find an example (.env) file: example.

License

Apache License 2.0