Files
util/src/main/kotlin/net/keinekekse/config/config.kt
T
2025-03-12 00:30:40 +01:00

41 lines
1020 B
Kotlin

package net.keinekekse.config
import java.io.InputStream
import java.util.*
private const val CONFIG_FILE_NAME = "config.properties"
private const val ERROR_LOADING_CONFIG = "Could not load configuration from $CONFIG_FILE_NAME"
// TODO mit WAR testen wg. Pfad zu config.properties
/**
* Projekt-Properties
*
* Die Datei ```config.properties``` wird aus dem JAR-root geladen.
* (-> in ```main/resources``` anlegen)
*
* ```
* val prop: String = ConfigProperties.get("some.prop")
* ```
*/
object ConfigProperties {
private val properties = Properties()
init {
loadConfigFile()
}
private fun loadConfigFile() {
val configFileStream: InputStream? =
javaClass.classLoader.getResourceAsStream(CONFIG_FILE_NAME)
if (configFileStream == null) {
throw IllegalStateException(ERROR_LOADING_CONFIG)
}
configFileStream.use {
properties.load(it)
}
}
fun get(key: String): String = properties.getProperty(key)
}