https://github.com/wtetzner/kurgan
Java Configuration Library
https://github.com/wtetzner/kurgan
Last synced: 5 months ago
JSON representation
Java Configuration Library
- Host: GitHub
- URL: https://github.com/wtetzner/kurgan
- Owner: wtetzner
- License: bsd-3-clause
- Created: 2014-08-20T23:38:37.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-12-14T20:44:50.000Z (over 3 years ago)
- Last Synced: 2023-10-20T23:51:12.533Z (over 2 years ago)
- Language: Java
- Size: 52.7 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
[](https://travis-ci.org/wtetzner/kurgan)
Kurgan
======
Kurgan is a Java library for loading YAML configuration files. It is
designed to be as easy as possible to use, while helping to ensure
correctness.
Usage
=====
To use with maven, add
```XML
org.bovinegenius
kurgan
0.7.0
```
to your pom.xml.
Example
=======
This is an example of a config for a server that serves files from the filesystem over HTTP, but it knows how to convert between various formats.
To load a YAML file, you first need to define one or more interfaces to represent your configuration.
You can then load the config by using
```java
ConfigLoader.loadYaml(ConfigInterface.class, "/path/to/config.yaml")
```
to load a file, or
```java
ConfigLoader.loadYaml(ConfigInterface.class, "classpath:/path/to/config.yaml")
```
to load from the classpath.
You can also use `ConfigLoader.loadAllYaml` to load a list of objects out of a YAML file that has multiple documents in it.
```java
package example;
import org.bovinegenius.kurgan.ConfigLoader;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.List;
public class Tester {
public static enum Format {
JSON,
XML,
HTML
}
public static interface Resource {
T location();
Format format();
}
public static interface HttpResource {
@FieldName("disk-resource")
Resource getDiskResource();
@FieldName("rest-resource")
Resource getRestResource();
}
public static interface Config {
@FieldName("read-only")
boolean readOnly();
@FieldName("max-file-size")
long maxFileSize();
List getResources();
}
public static void main(String[] args) throws IOException {
Config config = ConfigLoader.loadYaml(Config.class, System.getProperty("user.home") + "/temp/test.yaml");
System.out.println(config);
}
}
```
Here's an example of what a valid config file might look like.
```yaml
read-only: true
max-file-size: 1000000
resources:
- disk-resource:
location: /www/files/numbers.json
format: JSON
rest-resource:
location: http://example.com/numbers.xml
format: XML
- disk-resource:
location: /www/files/users.xml
format: XML
rest-resource:
location: http://example.com/users.html
format: HTML
```
Building
========
mvn package
Publishing
==========
mvn deploy -Dgpg.skip=false