项目作者: TheElectronWill

项目描述 :
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
高级语言: Java
项目地址: git://github.com/TheElectronWill/night-config.git
创建时间: 2016-11-20T15:52:01Z
项目社区:https://github.com/TheElectronWill/night-config

开源协议:GNU Lesser General Public License v3.0

下载


Night Config

Maven Central
javadoc
CircleCI

Introduction

NightConfig is a powerful yet easy-to-use java configuration library, written in Java 8.

It supports the following formats:

How to use

Glimpse

  1. // Simple builder:
  2. FileConfig conf = FileConfig.of("the/file/config.toml");
  3. // Advanced builder, default resource, autosave and much more (-> cf the wiki)
  4. CommentedFileConfig config = CommentedFileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
  5. config.load(); // This actually reads the config
  6. String name = config.get("username"); // Generic return type!
  7. List<String> names = config.get("users_list"); // Generic return type!
  8. long id = config.getLong("account.id"); // Compound path: key "id" in subconfig "account"
  9. int points = config.getIntOrElse("account.score", defaultScore); // Default value
  10. config.set("account.score", points*2);
  11. String comment = config.getComment("user");
  12. // NightConfig saves the config's comments (for TOML and HOCON)
  13. // config.save(); not needed here thanks to autosave()
  14. config.close(); // Close the FileConfig once you're done with it :)

Running the examples

Each file in examples/src/main/java has a main function and shows how to use NightConfig for many different use cases.

To run an example:

  1. Clone this repository.
  2. cd to it
  3. Run ./gradlew examples:run -PmainClass=${CLASS} by replacing ${CLASS} with the example of your choice.

For example, to run FileConfigExample.java:

  1. ./gradlew examples:run -PmainClass=FileConfigExample

The file be compiled automatically, and the given main class will be executed.

Project building

NightConfig is built with Gradle. The project is divided in several modules, the “core” module plus one module per supported configuration format. Please read the wiki for more information.

The releases are available on Maven Central and JitPack.

Old Android modules

Older versions of Android (before Android Oreo) didn’t provide the packages java.util.function and java.nio.file, which NightConfig heavily uses.
To attempt to mitigate these issues, I made a special version of each modules, suffixed with _android, that you could use instead of the regular modules.

These old _android modules are deprecated and will no longer receive updates.
The maintainance burden of these modules is not worth it, and these versions of Android have reached end of life since several years already.