-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide DotenvEntry toString(), fix execption message, and add maven …
…example (#3) * implement DotenvEntry toString * (fix) exception message * simple maven example * increment patch version
- Loading branch information
Showing
7 changed files
with
83 additions
and
2 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,27 @@ | ||
# dotenv-java-example | ||
|
||
Simple `dotenv-java` example using maven. | ||
|
||
## Clone | ||
|
||
```shell | ||
git clone | ||
``` | ||
|
||
## Compile | ||
|
||
```shell | ||
mvn compile | ||
``` | ||
|
||
## Run | ||
|
||
```shell | ||
mvn exec:java -Dexec.mainClass="io.github.cdimascio.examples.dotenv.Main" | ||
``` | ||
|
||
The program outputs the value of the env var `MY_ENV`. In this case, `MY_VALUE` | ||
|
||
## License | ||
|
||
MIT |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cdimascio.github.io</groupId> | ||
<artifactId>dotenv-java-example</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.cdimascio</groupId> | ||
<artifactId>dotenv-java</artifactId> | ||
<version>1.0.3</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
examples/maven-simple/src/main/java/io/github/cdimascio/examples/dotenv/Main.java
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,25 @@ | ||
|
||
package io.github.cdimascio.examples.dotenv; | ||
|
||
import io.github.cdimascio.dotenv.Dotenv; | ||
import io.github.cdimascio.dotenv.DotenvEntry; | ||
|
||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Dotenv dotenv = Dotenv.configure().load(); | ||
|
||
// Iterate over each environment entry | ||
// Note: entries in the host environment override entries in .env | ||
for (DotenvEntry e : dotenv.entries()) { | ||
System.out.println(e); | ||
} | ||
|
||
// Retrieve the value of the MY_ENV environment variable | ||
System.out.println(dotenv.get("MY_ENV")); | ||
|
||
// Retrieve the value of the MY_ENV2 environment variable or return a default value | ||
System.out.println(dotenv.get("MY_ENV2", "Default Value")); | ||
} | ||
} |
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 @@ | ||
MY_ENV="MY_VALUE" |
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
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
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