GithubHelp home page GithubHelp logo

nateriver520 / jconf Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 384 KB

A lightweight and universal configuration library for JVM that supports INI, XML, JSON ,YAML and Properties file.

Home Page: http://jconf.readthedocs.org/en/latest/

License: MIT License

Groovy 100.00%

jconf's Introduction

Build Status Documentation Status

JConf

JConf is a easy and light library for config module in Java or Groovy applications.

Currently this library support JSON, YAML, INI, XML, Properties

Visit http://jconf.readthedocs.org/en/latest/ for more detail info

Usage

  • For maven

add dependency

    <dependency>
        <groupId>com.github.nateriver520</groupId>
        <artifactId>jconf</artifactId>
        <version>0.2.1</version>
    </dependency>

Example

if I want to load a json config like this:

    {
      "person": {
        "name": "Guillaume",
        "age": 33,
        "score": 93.3,
        "id": 110000012129,
        "pets": [
          "dog",
          "cat"
        ],
        "is_admin": true
      },
      "work": "cs"
    }

Here is example

    // support yaml, ini
    // also support load from text or stream
    def conf = new Config('conf.json')

    conf.getString("person.name") // "Guillaume"
    conf.getInteger("person.age") // 33
    conf.getDouble("person.score") // 93.3
    conf.getFloat("person.score") // 93.3
    conf.getLong("person.id") // 110000012129
    conf.getBoolean("person.is_admin") // true
    conf.getList("person.pets") // ["dog", "cat"]
    conf.getString("work") //"cs"

    // default value
    // don't exist so return default value: "[email protected]"
    conf.getString("persion.mail", "[email protected]")

    // use other separator
    // set separator with ::
    conf.separator = "::"

    conf.getString("person::name") // "Guillaume"

    // we also can set config manually
    conf.set("person::name", "jack")
    conf.get("person::name") // "jack"

    // delete conf
    conf.del("person::name")
    conf.exist("person::name") // false

    // we can reset config to the origin version without change
    conf.reset()

LICENSE

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.