File tree 7 files changed +83
-2
lines changed
java/io/github/cdimascio/examples/dotenv
src/main/java/io/github/cdimascio/dotenv
7 files changed +83
-2
lines changed Original file line number Diff line number Diff line change
1
+ # dotenv-java-example
2
+
3
+ Simple ` dotenv-java ` example using maven.
4
+
5
+ ## Clone
6
+
7
+ ``` shell
8
+ git clone
9
+ ```
10
+
11
+ ## Compile
12
+
13
+ ``` shell
14
+ mvn compile
15
+ ```
16
+
17
+ ## Run
18
+
19
+ ``` shell
20
+ mvn exec:java -Dexec.mainClass=" io.github.cdimascio.examples.dotenv.Main"
21
+ ```
22
+
23
+ The program outputs the value of the env var ` MY_ENV ` . In this case, ` MY_VALUE `
24
+
25
+ ## License
26
+
27
+ MIT
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns =" http://maven.apache.org/POM/4.0.0"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <modelVersion >4.0.0</modelVersion >
6
+
7
+ <groupId >cdimascio.github.io</groupId >
8
+ <artifactId >dotenv-java-example</artifactId >
9
+ <version >1.0-SNAPSHOT</version >
10
+
11
+ <properties >
12
+ <maven .compiler.source>11</maven .compiler.source>
13
+ <maven .compiler.target>11</maven .compiler.target>
14
+ </properties >
15
+
16
+ <dependencies >
17
+ <dependency >
18
+ <groupId >io.github.cdimascio</groupId >
19
+ <artifactId >dotenv-java</artifactId >
20
+ <version >1.0.3</version >
21
+ </dependency >
22
+ </dependencies >
23
+ </project >
Original file line number Diff line number Diff line change
1
+
2
+ package io .github .cdimascio .examples .dotenv ;
3
+
4
+ import io .github .cdimascio .dotenv .Dotenv ;
5
+ import io .github .cdimascio .dotenv .DotenvEntry ;
6
+
7
+
8
+ public class Main {
9
+
10
+ public static void main (String [] args ) {
11
+ Dotenv dotenv = Dotenv .configure ().load ();
12
+
13
+ // Iterate over each environment entry
14
+ // Note: entries in the host environment override entries in .env
15
+ for (DotenvEntry e : dotenv .entries ()) {
16
+ System .out .println (e );
17
+ }
18
+
19
+ // Retrieve the value of the MY_ENV environment variable
20
+ System .out .println (dotenv .get ("MY_ENV" ));
21
+
22
+ // Retrieve the value of the MY_ENV2 environment variable or return a default value
23
+ System .out .println (dotenv .get ("MY_ENV2" , "Default Value" ));
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ MY_ENV = " MY_VALUE"
Original file line number Diff line number Diff line change 10
10
11
11
<groupId >io.github.cdimascio</groupId >
12
12
<artifactId >dotenv-java</artifactId >
13
- <version >1.0.2 </version >
13
+ <version >1.0.3 </version >
14
14
15
15
<licenses >
16
16
<license >
Original file line number Diff line number Diff line change @@ -16,5 +16,10 @@ public String getKey() {
16
16
public String getValue () {
17
17
return value ;
18
18
}
19
+
20
+ @ Override
21
+ public String toString () {
22
+ return key +"=" +value ;
23
+ }
19
24
}
20
25
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ static Stream<String> loadFileFromClasspath(String location) {
18
18
}
19
19
20
20
if (inputStream == null ) {
21
- throw new DotenvException ("Could not find $ location on the classpath" );
21
+ throw new DotenvException ("Could not find " + location + " on the classpath" );
22
22
}
23
23
var scanner = new Scanner (inputStream , "utf-8" );
24
24
var lines = new ArrayList <String >();
You can’t perform that action at this time.
0 commit comments