8000 GitHub - henryx/envfile: A Java library to load .env files
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

henryx/envfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnvFile

A 12-factor Java API configuration library

Compatibility

This library is written for Java 8 or great

Install

With maven, you should compile with:

mvn clean install

After compiled, you can add it in your pom.xml these lines:

<dependency>
  <groupId>org.library</groupId>
  <artifactId>envfile</artifactId>
  <version>0.1.2</version>
</dependency>

Usage

Suppose you have an .env file in your project like this:

VAR1="this is a value"
VAR2=123

you can load it with this code:

import org.library.envfile.EnvFile;

public class Example {
    public static void main(String[] args) {
        EnvFile.load();
        System.out.println(System.getenv("VAR1"));
        System.out.println(System.getenv("VAR2"));
    }
}

Another usage is to specify entire path of the env file:

import org.library.envfile.EnvFile;

public class Example2 {
    public static void main(String[] args) {
        EnvFile.load("/path/for/.env");
        System.out.println(System.getenv("VAR1"));
        System.out.println(System.getenv("VAR2"));
    }
}

Notes

This library is written with help of this issue of StackOverflow. This means that when you use this library, you might receive this warning:

WARNING: An illegal reflective access operation has occurred

To suppress this warning, use --illegal-access=warn as JVM option. Sadly, at the moment, I cannot know another method to avoid it

About

A Java library to load .env files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0