-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carmine DiMascio
committed
Nov 25, 2017
1 parent
520746b
commit 477facd
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# java-dotenv | ||
|
||
|
||
Dotenv is a zero-dependency module that loads environment variables from a `.env`. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology. | ||
|
||
**Note:** Java does not provide a way to set environment variables on a currently running process. Thus, once `java-dotenv` is configured, you can use the `dotenv.get("...")` API to get environment variables, instead of `System.getenv(...)`. | ||
|
||
## Usage | ||
|
||
### Create a `.env` file | ||
|
||
``` | ||
# formatted as key=value | ||
MY_ENV_VAR1=My first env var with dotenv | ||
MY_EVV_VAR2=My second env var | ||
``` | ||
|
||
### Kotlin | ||
#### Configure dotenv-java | ||
Configure `dotenv-java` once in your application. | ||
|
||
```kotlin | ||
val dotenv = Dotenv | ||
.configure() | ||
.withDirectory("./src/test/resources") | ||
.ignoreIfMalformed() | ||
.build() | ||
``` | ||
|
||
#### Get an environment variable | ||
Note, environment variables specified in `.env` take precedence over those configured in the actual environment. | ||
|
||
``` | ||
dotenv["MY_ENV_VAR1"] | ||
``` | ||
|
||
### Java | ||
#### Configure dotenv-java | ||
Configure `dotenv-java` once in your application. | ||
|
||
```java | ||
Dotenv dotenv = Dotenv | ||
.configure() | ||
.withDirectory("./src/test/resources") | ||
.ignoreIfMalformed() | ||
.build() | ||
``` | ||
|
||
#### Get an environment variable | ||
Note, environment variables specified in `.env` take precedence over those configured in the actual environment. | ||
|
||
``` | ||
dotenv.get("MY_ENV_VAR1") | ||
``` | ||
|
||
## License | ||
Apache 2.0 |