Added Snakeyaml to project to load YAML config file
This commit is contained in:
parent
9c52a48425
commit
155780463a
5
pom.xml
5
pom.xml
@ -20,6 +20,11 @@
|
|||||||
<artifactId>javafx-fxml</artifactId>
|
<artifactId>javafx-fxml</artifactId>
|
||||||
<version>17</version>
|
<version>17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.33</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -9,6 +9,8 @@ import javafx.scene.Scene;
|
|||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import net.metaunix.Config;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaFX App
|
* JavaFX App
|
||||||
@ -22,6 +24,9 @@ public class App extends Application {
|
|||||||
|
|
||||||
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
|
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"));
|
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("views/main.fxml"));
|
||||||
var scene = new Scene(root, 640, 480);
|
var scene = new Scene(root, 640, 480);
|
||||||
stage.setTitle("Acorn Music Player");
|
stage.setTitle("Acorn Music Player");
|
||||||
|
23
src/main/java/net/metaunix/Config.java
Normal file
23
src/main/java/net/metaunix/Config.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
src/main/resources/default.yaml
Normal file
1
src/main/resources/default.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
library_path: "~/Music"
|
Loading…
Reference in New Issue
Block a user