Added Snakeyaml to project to load YAML config file

This commit is contained in:
Gregory Ballantine 2023-01-13 23:25:03 -05:00
parent 9c52a48425
commit 155780463a
4 changed files with 34 additions and 0 deletions

View File

@ -20,6 +20,11 @@
<artifactId>javafx-fxml</artifactId>
<version>17</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -9,6 +9,8 @@ import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import net.metaunix.Config;
/**
* JavaFX App
@ -22,6 +24,9 @@ public class App extends Application {
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
Config cfg = new Config("default.yaml");
System.out.println(cfg.get("library_path"));
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("views/main.fxml"));
var scene = new Scene(root, 640, 480);
stage.setTitle("Acorn Music Player");

View File

@ -0,0 +1,23 @@
package net.metaunix;
import java.io.InputStream;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
public class Config {
private Map<String, Object> cfg;
public Config(String configPath) {
Yaml yaml = new Yaml();
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream(configPath);
this.cfg = yaml.load(inputStream);
}
public Object get(String key) {
return this.cfg.get(key);
}
}

View File

@ -0,0 +1 @@
library_path: "~/Music"