
config.Config Maven / Gradle / Ivy
The newest version!
package config;
import org.jetbrains.annotations.Nullable;
import util.Log;
import java.util.Properties;
/**
* Zugriffspunkt auf die Configs
*
* @author Simon Danner, 09.04.2016.
*/
public class Config
{
private final static String DEFAULT_PATH = "/config.properties";
private static Properties properties = null;
private static ClassLoader classLoader = null;
public static void setClassLoader(Class pClass)
{
classLoader = pClass.getClassLoader();
properties = _load(DEFAULT_PATH);
}
@Nullable
public static String get(String pProperty)
{
if (classLoader == null)
throw new RuntimeException("Config-Classloader must not be null");
return properties.getProperty(pProperty);
}
@Nullable
public static String get(String pProperty, String pResourcePath)
{
return _load(pResourcePath).getProperty(pProperty);
}
private static Properties _load(String pPath)
{
try
{
Properties props = new Properties();
props.load(classLoader.getResourceAsStream(pPath));
return props;
}
catch (Exception e)
{
Log.error("Config-file could not be loaded. Path: " + pPath);
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy