Java 응용 프로그램은 런타임시 hadoop xml의 폴더를 정의해야합니다 (단순화를 위해 프로그램 명령 행 인수에서 가져옵니다).프로그래밍 방식으로 hadoop * -site.xml의 디렉토리를 설정하는 방법
import org.apache.hadoop.conf.Configuration()
....
Configuration = new Configuration
config.addResource(new Path(String.format("%s/core-site.xml", hadoopLocation)));
config.addResource(new Path(String.format("%s/hdfs-site.xml", hadoopLocation)));
config.addResource(new Path(String.format("%s/tez-site.xml", hadoopLocation)));
config.addResource(new Path(String.format("%s/yarn-site.xml", hadoopLocation)));
config.addResource(new Path(String.format("%s/mapred-site.xml", hadoopLocation)));
config.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
config.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
try {
FileSystem dfs = FileSystem.get(config);
} catch (IOException e) {
LOGGER.error("Failed to process hadoop file system");
}
그러나, 나는 내 프로그램에서 호출 할 때마다 new Configuration()
그것을 반복하거나 일부 지속적인 사전 baseConfiguration
객체를 사용하고 new Configuration(baseConfiguration)
처럼 사용한다 : 나는 다음과 같은 코드를 사용할 수 같아요. 이 모든 방법들은 꽤 서투르게 보입니다. 더 우아한 해결책이 있습니까? 정적 메서드 호출과 같은 무언가를 한 번 수행 할 수 있습니다. 다음 코드는 설명 용으로 만 제공됩니다.
Configuration.setBaseXmlsDir();