initial commit
This commit is contained in:
commit
c81f3ea29e
21 files changed
+903
No files matched your search
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user