File f1 = new File(path);
if (f1.exists()) {
try {
return f1.toURI().toURL();
} catch (MalformedURLException e) {
throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e);
}
}
if (path.startsWith("/")) {
path = path.substring(1);
}
// next, try it relative to the config location
File f2 = new File(configFile, path);
if (f2.exists()) {
try {
return f2.toURI().toURL();
} catch (MalformedURLException e) {
throw new FailedToResolveConfigException("Failed to resolve path [" + f2 + "]", e);
}
}
// try and load it from the classpath directly
URL resource = Classes.getDefaultClassLoader().getResource(path);
if (resource != null) {
return resource;
}
// try and load it from the classpath with config/ prefix
if (!path.startsWith("config/")) {
resource = Classes.getDefaultClassLoader().getResource("config/" + path);
if (resource != null) {
return resource;
}
}
throw new FailedToResolveConfigException("Failed to resolve config path [" + path + "], tried file path [" + f1 + "], path file [" + f2 + "], and classpath");
}