Popularity
2.1
Declining
Activity
0.0
Stable
45
4
2

Programming language: Java
Tags: Configuration    
Latest version: v0.1.1

dotenv alternatives and similar libraries

Based on the "Configuration" category.
Alternatively, view dotenv alternatives based on common mentions on social networks and blogs.

  • config

    configuration library for JVM languages using HOCON files
  • owner

    Get rid of the boilerplate code in properties based configuration.
  • Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
    Promo www.influxdata.com
    InfluxDB Logo
  • centraldogma

    Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2
  • cfg4j

    Modern configuration library for distributed apps written in Java.
  • KAConf

    KickAss Configuration. An annotation-based configuration system for Java and Kotlin
  • Gestalt

    A Java configuration library that allows you to build your configurations from multiple sources, merges them and convert them into an easy-to-use typesafe configuration class. A simple but powerful interface allows you to navigate to a path within your configurations and retrieve a configuration object, list, or a primitive value.
  • Configur8

    Nano-library which provides the ability to define typesafe (!) configuration templates for applications.
  • Coat

    Config of Annotated Types
  • ini4j

    Provides an API for handling Windows' INI files.

Do you think we are missing an alternative of dotenv or a related project?

Add another 'Configuration' Library

README

dotenv Build Status Maven Central

A twelve-factor configuration library for Java 8+.

Features:

Usage

<dependency>
    <groupId>com.github.shyiko.dotenv</groupId>
    <artifactId>dotenv</artifactId>
    <version>0.1.1</version>
</dependency>

ENV resolution order (sources higher in the list take precedence over those located lower):

  • System.getenv()
  • .env file in current working directory (might not exist)
  • .env file on the classpath

(java example)

Let's assume you have a jar file (say app.jar) which contains .env file (e.g. printf "SCHEME=http\nHOST=localhost\n# comment\nPORT=8080" > src/main/resources/.env) and Main.java with the following public static void main(...):

Map<String, String> dotEnv = DotEnv.load();
System.out.println(dotEnv.get("SCHEME") + "://" + dotEnv.get("HOST") + ":" + dotEnv.get("PORT"))

Executing the following

printf "HOST=0.0.0.0" > .env
PORT=5050 app.jar

will then output http://0.0.0.0:5050

Integration with Guice

<dependency>
    <groupId>com.github.shyiko.dotenv</groupId>
    <artifactId>dotenv-guice</artifactId>
    <version>0.1.1</version>
</dependency>

(Main.java)

static class S {
    private final String scheme;
    private final String host;
    private final int port;

    @Inject
    public S(
        @DotEnvValue("SCHEME") String scheme, 
        @DotEnvValue("HOST") String host, 
        @DotEnvValue("PORT") int port
    ) {
        this.scheme = scheme;
        this.host = host;
        this.port = port;
    }

    public void run() {
        System.out.println(scheme + "://" + host + ":" + port);
    }
}

public static void main(String[] args) {
    Injector injector = Guice.createInjector(new DotEnvModule()/*, ... */);
    S s = injector.getInstance(S.class);
    s.run();
}

Integration with Spring

(Main.java)

static class S {
    private final String scheme;
    private final String host;
    private final int port;

    @Autowired
    public S(
        @Value("${SCHEME}") String scheme, 
        @Value("${HOST}") String host, 
        @Value("${PORT}") int port
    ) {
        this.scheme = scheme;
        this.host = host;
        this.port = port;
    }

    public void run() {
        System.out.println(scheme + "://" + host + ":" + port);
    }
}

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.getEnvironment().getPropertySources().addFirst(
        new MapPropertySource("dotenv", new HashMap<>(DotEnv.load()))
    );
    ctx.refresh();
    S s = ctx.getBeanFactory().createBean(S.class);
    s.run();
}

Development

git clone https://github.com/shyiko/dotenv && cd dotenv
./mvnw # shows how to build, test, etc. project

Legal

All code, unless specified otherwise, is licensed under the MIT license.
Copyright (c) 2017 Stanley Shyiko.


*Note that all licence references and agreements mentioned in the dotenv README section above are relevant to that project's source code only.