diff --git a/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java b/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java index e4176499487ee..f3614a64b703f 100644 --- a/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java +++ b/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; +import java.net.URL; import java.util.HashSet; import java.util.Set; @@ -90,11 +91,24 @@ public DFSPropertiesConfiguration() { } /** - * Load global props from hudi-defaults.conf which is under CONF_FILE_DIR_ENV_NAME. + * Load global props from hudi-defaults.conf which is under class loader or CONF_FILE_DIR_ENV_NAME. * @return Typed Properties */ public static TypedProperties loadGlobalProps() { DFSPropertiesConfiguration conf = new DFSPropertiesConfiguration(); + + // First try loading the external config file from class loader + URL configFile = Thread.currentThread().getContextClassLoader().getResource(DEFAULT_PROPERTIES_FILE); + if (configFile != null) { + try (BufferedReader br = new BufferedReader(new InputStreamReader(configFile.openStream()))) { + conf.addPropsFromStream(br); + return conf.getProps(); + } catch (IOException ioe) { + throw new HoodieIOException( + String.format("Failed to read %s from class loader", DEFAULT_PROPERTIES_FILE), ioe); + } + } + // Try loading the external config file from local file system Option defaultConfPath = getConfPathFromEnv(); if (defaultConfPath.isPresent()) { conf.addPropsFromFile(defaultConfPath.get());